- 浏览: 206951 次
- 性别:
- 来自: 杭州
文章分类
最新评论
-
hus20120405:
很不错,我运行起来了
log4jdbc日志框架介绍 -
Roshomon:
牛叉 找了很多解决方案 你的OK了
plsql ora-12154 TNS 无法处理服务名 -
ackley:
赞!谢谢!
Cannot access NLS data files or invalid ...
学习了 dubbo rest服务之后,再使用dubbo http协议,就非常简单了,只要将服务的暴露协议改为http即可,不需要根据jax-rs规范,引入@Path等一堆annotation。
1. dubbo 配置文件
这个文件是在前面练习的dubbo rest服务基础上增加的,只要增加
注意:如果以下这一行
2.接口类
3.实现类
4.客户端dubbo配置
5. 调用代码
6. 如果采用webservice协议暴露,只要将
1. dubbo 配置文件
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dubbo="http://code.alibabatech.com/schema/dubbo" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd"> <dubbo:application name="dubborest-webapp" owner="zhenggm" organization="zjport"/> <dubbo:registry address="zookeeper://192.168.3.140:2181"/> <!--uncomment this if you want to test dubbo's monitor--> <!--<dubbo:monitor protocol="registry"/>--> <!-- here we demonstrate both annotation-based and xml-based configs --> <dubbo:annotation package="cn.gov.zjport.dubborest.service" /> <!-- use tomcat server --> <dubbo:protocol name="rest" port="7056" contextpath="dubborest-webapp" server="servlet" extension="com.alibaba.dubbo.rpc.protocol.rest.support.LoggingFilter"/> <dubbo:service interface="cn.gov.zjport.dubborest.service.rest.RestDemoService" ref="restDemoService" protocol="rest" timeout="2000" connections="100" validation="true"/> <dubbo:service interface="cn.gov.zjport.dubborest.service.http.HttpDemoService" ref="httpDemoService" protocol="http" timeout="2000" connections="100" validation="true"/> </beans>
这个文件是在前面练习的dubbo rest服务基础上增加的,只要增加
<dubbo:service interface="cn.gov.zjport.dubborest.service.http.HttpDemoService" ref="httpDemoService" protocol="http" timeout="2000" connections="100" validation="true"/>即完成服务的发布。
注意:如果以下这一行
<dubbo:protocol name="rest" port="7056" contextpath="dubborest-webapp" server="servlet" extension="com.alibaba.dubbo.rpc.protocol.rest.support.LoggingFilter"/>如果将name改为http, 那么会提示nullpoint的错误,是配置文件中另外一个restDemoService采用rest方式调用的原因造成。
2.接口类
package cn.gov.zjport.dubborest.service.http; import cn.gov.zjport.dubborest.pojo.User; public interface HttpDemoService { public User execute(User user); }
3.实现类
package cn.gov.zjport.dubborest.service.http.impl; import org.springframework.stereotype.Service; import cn.gov.zjport.dubborest.pojo.User; import cn.gov.zjport.dubborest.service.http.HttpDemoService; @Service("httpDemoService") public class HttpDemoServiceImpl implements HttpDemoService{ public User execute(User user){ user.setName(user.getName()+",hello"); return user; } }
4.客户端dubbo配置
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dubbo="http://code.alibabatech.com/schema/dubbo" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd"> <dubbo:application name="dubborest-webapp" owner="zhenggm" organization="zjport"/> <dubbo:registry address="zookeeper://192.168.3.140:2181"/> <!--uncomment this if you want to test dubbo's monitor--> <!--<dubbo:monitor protocol="registry"/>--> <!-- here we demonstrate both annotation-based and xml-based configs --> <dubbo:annotation package="cn.gov.zjport.dubborest.service" /> <!-- use tomcat server --> <dubbo:protocol name="rest" port="7056" contextpath="dubborest-webapp" server="servlet" extension="com.alibaba.dubbo.rpc.protocol.rest.support.LoggingFilter"/> <dubbo:service interface="cn.gov.zjport.dubborest.service.rest.RestDemoService" ref="restDemoService" protocol="rest" timeout="2000" connections="100" validation="true"/> <dubbo:service interface="cn.gov.zjport.dubborest.service.http.HttpDemoService" ref="httpDemoService" protocol="http" timeout="2000" connections="100" validation="true"/> </beans>也是基于dubbo rest客户端配置修改的,增加了最后一行服务调用
5. 调用代码
System.out.println(httpDemoService.execute(user).getName());
6. 如果采用webservice协议暴露,只要将
<dubbo:service interface="cn.gov.zjport.dubborest.service.http.HttpDemoService" ref="httpDemoService" protocol="http" timeout="2000" connections="100" validation="true"/>中的protocol="http"改为protocol="webservice"即可,其他调用代码如http保持不变。
发表评论
文章已被作者锁定,不允许评论。
-
zookeeper docker 集群安装
2022-10-14 17:18 1081. 下载镜像 docker pull docker.io/z ... -
Kafka学习笔记【三】-JAVA调用示例
2018-05-29 08:35 5691. pom.xml <dependency> ... -
Kafka学习笔记【二】-安装
2018-05-24 08:20 354kafka的安装如下: 一、准备环境 1) 三台服务器 ... -
Kafka学习笔记【一】-原理
2018-05-18 09:23 249一、kafka的重要概念 1. kafka 分为 Produ ... -
rabbitMQ学习笔记【三】-haproxy部署 原创
2018-04-11 16:11 374一、下载 https://fossies.org/lin ... -
rabbitMQ学习笔记【二】-集群部署 原创
2018-04-03 19:40 397一、准备工作 三台机器hosts: 192.168.3 ... -
rabbitMQ学习笔记【一】-单机部署 原创
2018-03-19 16:04 405公司对外接入需要支持MQ,最终选定rabbitMQ.本文 ... -
HttpClient 学习笔记【原创】
2017-09-07 19:28 1821HttpClient 某些方法的作用梳理。本文的测试基于htt ... -
关于dubbo的思考【原创】
2016-09-21 08:23 1283最近在看dubbo的文档,有些内容结合自己的思考记录一下 1. ... -
dubbo rest 服务学习笔记(三)【原创】
2016-09-09 19:34 8679在配置过程中遇到两个 ... -
dubbo rest 服务学习笔记(二)【原创】
2016-09-09 19:21 1344采用dubbo客户端访问dubbo发布的rest服务,接上一篇 ... -
dubbo rest 服务学习笔记(一)【原创】
2016-09-09 19:07 5997dubbo是很好的服务治理工具,包含了注册,路由,监控 ... -
RocketMq数据处理
2016-06-27 08:58 562这篇讲实践中数据丢失、顺序幂等处理、性能压测,有时间再写 -
RocketMq学习笔记(2)【原创】
2016-06-27 08:55 1100前一篇文章http://zhenggm.i ... -
MS MQ 使用实践【原创】
2016-06-26 14:58 7281. 参照百度经验http://jingyan.baidu.c ... -
RocketMq学习笔记【原创】
2016-06-23 14:05 1533前段时间在实施分布式数据库的过程中,使用过rocketMQ, ... -
rest的调用 java 示例代码【原创】
2016-06-20 15:35 10331. 服务端示例代码(如何搭建rest服务,请看上一篇) ... -
jersey2 与 spring4 整合实践【原创】
2016-06-13 15:35 4933前几年用过jeysey,那都是1.x版本的,jersey2有很 ... -
java nio入门
2010-03-04 17:22 952首先了解下所谓的java nio是个什么东西! ... -
spring http invoker学习笔记
2010-01-04 16:58 3623概念 Spring HTTP invoker是spring框架 ...
相关推荐
基于Dubbo的webservice开发 内附文档
Dubbo之《尚硅谷》学习笔记
用户不得未经著作权人同意擅自对他人的作品进行全部或部分复制、修改、改编、翻译、汇编、反向工程、反向编译、反向汇编或改写并进行上传。用户可以为介绍、评论、研究等目的,在合理范围内依法引用他人已经发表的...
阿里巴巴远程调用框架学习笔记,供入门童鞋使用
dubbo学习笔记.doc
Dubbo学习手册,Dubbo学习手册,积分;Dubbo学习手册Dubbo学习手册Dubbo学习手册Dubbo学习手册Dubbo学习手册
dubbo注册中心服务ip和实际服务提供者ip不一致问题 网上收集的资料
Dubbo分布式服务架构,对于研究大型Web服务器的并发技术的同学们有帮助。
此文档是从学习 dubbo 源码过程中的笔记中整理出来的,由于时间及能力 原因,理解有误之处还请谅解,希望对大家学习使用 dubbo 有所帮助。 dubbo 是阿里基于开源思想 java 实现的服务治理中间件, 目前除了阿里之 外...
dubbo学习例题代码资源
包含 Dubbo实现原理、高性能网络通讯、框架设计原则、Dubbo_功能介绍等七个dubbo学习的相关资料
本地直接连接服务提供者,模拟发送数据测试,dubbo接口调试
dubbo-rpc-webservice-2.8.4 dubbo-rpc-webservice-2.8.4
dubbo提供 rest 服务接口
dubbo的操作和使用流程详解(Dubbo简介及结构图、Dubbo支持的几种Registry、Zookeeper简介、Zookeeper安装、Dubbo支持的几种Protocol、Dubbo项目搭建、Admin管理界面、Assembly打包、监控中心搭建)
dubbo
dubbo 服务提供方和服务消费方的代码
dubbo框架源码,之前的积分太高,我改低了
dubbo dubbo学习笔记