博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
dubbo集成restful协议例子
阅读量:3728 次
发布时间:2019-05-22

本文共 3745 字,大约阅读时间需要 12 分钟。

dubbo集成restful协议例子

一、代码地址

  • dubbo-learn-parent 父类
  • dubbo-learn-config 配置
  • dubbo-learn-facade 实体类与接口
  • dubbo-learn-oauth 待续(接口认证)
  • dubbo-learn-service 服务提供者
  • dubbo-learn-web-service 服务消费者和rest服务提供者

二、基于dubbo协议的配置说明

1、消息提供者

dubbo-provider.xml

  • 只订阅
  • 只注册
  • 协议选择: dubbo\rmi\http\webservice\thrift

2、消费者

dubbo-consumer-dev.xml

  • 启动时检查
  • 集群容错
  • 负载均衡
  • 配置直连

web.xml

Archetype Created Web Application
spring.profiles.active
dev
com.alibaba.dubbo.remoting.http.servlet.BootstrapListener
org.springframework.web.context.ContextLoaderListener
dis
com.alibaba.dubbo.remoting.http.servlet.DispatcherServlet
1
dis
/*
dispatcher
org.springframework.web.servlet.DispatcherServlet
1
dispatcher
/oauth/token
contextConfigLocation
classpath:spring/spring-context.xml
springSecurityFilterChain
org.springframework.web.filter.DelegatingFilterProxy
springSecurityFilterChain
/*

三、基于restful协议的配置说明

dubbo-provider.xml

  • 线程模型

实现类: EnterpriseRestServiceImpl

package com.ctoedu.learn.restservice.impl;import com.alibaba.dubbo.rpc.protocol.rest.support.ContentType;import com.ctoedu.learn.mybatis.domain.Enterprise;import com.ctoedu.learn.repo.IEnterpriseService;import com.ctoedu.learn.restservice.IEnterpriseRestService;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Service;import org.springframework.web.bind.annotation.RequestBody;import javax.ws.rs.*;import javax.ws.rs.core.MediaType;@Path("/")//@Consumes({ MediaType.APPLICATION_JSON, MediaType.TEXT_XML, MediaType.APPLICATION_FORM_URLENCODED })//@Produces({ ContentType.APPLICATION_JSON_UTF_8, ContentType.TEXT_XML_UTF_8 })@Consumes({MediaType.APPLICATION_JSON, MediaType.TEXT_XML})@Produces({ContentType.APPLICATION_JSON_UTF_8, ContentType.TEXT_XML_UTF_8})@Service("enterpriseRestService")public class EnterpriseRestServiceImpl implements IEnterpriseRestService {   	@Autowired	IEnterpriseService enterpriseService;	@Path("/getenterprise/{id}")	@GET	public Enterprise getEnterpriseById(@PathParam("id") int id) {		return enterpriseService.getEnterpriseById(id);	}	@Path("/insertenterprise")	@POST	public void insertEnterprise(@RequestBody Enterprise enterprise) {		// TODO Auto-generated method stub			enterpriseService.insertEnterprise(enterprise);	}	@Path("/getstring/{name}")	@GET	public String getString(@PathParam("name") String name) {		return name;	}	@Path("/deleteenterprise/{id}")	@DELETE	public void deleteEnterprise(@PathParam("id") int enterpriseId) {		enterpriseService.deleteEnterprise(enterpriseId);	}}

转载地址:http://slonn.baihongyu.com/

你可能感兴趣的文章
emqx运行起来了,curl也是通的,但外网访问不
查看>>
10个解放双手的实用在线工具
查看>>
oracleTB级数据恢复遇到的坑
查看>>
Oracle归档日志
查看>>
Python-pyqt5+opencv视频播放器,上传本地视频(三)
查看>>
ModuleNotFoundError: No module namedNo module named ‘tensorflow_core.estimator‘,亲测有效
查看>>
Python-PyQt5+Mysql-数据交互,获取数据,并写入数据库,再并展示数据(四)
查看>>
AWK超详解
查看>>
linux经典面试题----开机启动流程
查看>>
静态配置ip地址
查看>>
linux手工新建用户(通过文件操作)
查看>>
计算机网络经典面试题目-----三次握手四次断开
查看>>
高可用和负载均衡学习笔记
查看>>
(详解)在浏览器输入www.biadu.com,背后发生了什么
查看>>
浅谈列表和元组的区别
查看>>
详解三次握手
查看>>
详解四次断开
查看>>
RAID学习笔记,面试必备
查看>>
LAMP和LNMP详解,面试必备
查看>>
系统运行缓慢该怎么排查
查看>>