Dubbo系列(3)_官方Demo说明
- JDK:1.6
- Dubbo版2号:2.5.4-SNAPSHOT
- Spring版本号:3.2.16.RELEASE<
- ZooKeeper版本号:3.3.3
- Jedis版本号:2.1.0
- Netty版本号:3.2.5.Final
- 其它:参考pom.xml https://github.com/alibaba/dubbo/blob/master/pom.xml
1
2
3
4
5
6
7
|
package com.alibaba.dubbo.demo; public interface DemoService { String sayHello(String name); } |
2、服务实现:dubbo-demo-provider
a) 服务端包含了对dubbo-demo-api的引用及实现
1
2
3
4
5
|
< dependency > < groupId >com.alibaba</ groupId > < artifactId >dubbo-demo-api</ artifactId > < version >${project.parent.version}</ version > </ dependency > |
b) 配置文件(dubbo-demo-provider.xml)
其中<dubbo:servcie> 定义一个对外提供的接口,通过ref关联到具体的实现代码
1
2
3
4
5
6
7
8
9
10
11
|
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd < bean id = "demoService" class = "com.alibaba.dubbo.demo.provider.DemoServiceImpl" /> < dubbo:service interface = "com.alibaba.dubbo.demo.DemoService" ref = "demoService" /> </ beans > |
c) 实现代码(DemoServiceImpl)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
package com.alibaba.dubbo.demo.provider; import java.text.SimpleDateFormat; import java.util.Date; import com.alibaba.dubbo.demo.DemoService; import com.alibaba.dubbo.rpc.RpcContext; public class DemoServiceImpl implements DemoService { public String sayHello(String name) { System.out.println( "[" + new SimpleDateFormat( "HH:mm:ss" ).format( new Date()) + "] Hello " + name + ", request from consumer: " + RpcContext.getContext().getRemoteAddress()); return "Hello " + name + ", response form provider: " + RpcContext.getContext().getLocalAddress(); } } |
3、服务消费:dubbo-demo-consumer
1
2
3
4
5
|
< dependency > < groupId >com.alibaba</ groupId > < artifactId >dubbo-demo-api</ artifactId > < version >${project.parent.version}</ version > </ dependency > |
b) 配置文件(dubbo-demo-consumer.xml)
通过<dubbo:reference>引用一个服务接口,客户端使用远程接口方法就和调用本地方法一致
1
2
3
4
5
6
7
8
9
|
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd < dubbo:reference id = "demoService" interface = "com.alibaba.dubbo.demo.DemoService" /> </ beans > |
c) 消费端调用代码:DemoAction.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
package com.alibaba.dubbo.demo.consumer; import java.text.SimpleDateFormat; import java.util.Date; import com.alibaba.dubbo.demo.DemoService; public class DemoAction { private DemoService demoService; public void setDemoService(DemoService demoService) { this .demoService = demoService; } public void start() throws Exception { for ( int i = 0 ; i < Integer.MAX_VALUE; i ++) { try { String hello = demoService.sayHello( "world" + i); System.out.println( "[" + new SimpleDateFormat( "HH:mm:ss" ).format( new Date()) + "] " + hello); } catch (Exception e) { e.printStackTrace(); } Thread.sleep( 2000 ); } } } |
Dubbo系列(3)_官方Demo说明的更多相关文章
- Dubbo系列(1)_背景介绍和基本情况
一.本文目的 主要介绍Dubbo的产生背景和需要解决的问题 二.产生背景 随着大数据量.高并发的互联网应用越来越多,单机系统已经无法满足系统的需要.通过SOA搭建一个分 ...
- Dubbo系列_概述
一.本文目的 学习使用Dubbo也有一段时间了,准备写一个系列文章介绍Dubbo的相关知识和使用,供自己以后回顾和他人学习.有兴趣的同学可以加入群:74085440一起探讨 二.书写计 ...
- Qt5官方demo分析集11——Qt Quick Particles Examples - Affectors
在这个系列中的所有文章都可以在这里查看http://blog.csdn.net/cloud_castle/article/category/2123873 接上文Qt5官方demo解析集10--Qt ...
- Qt5官方demo分析集29——Extending QML - Property Value Source Example
此系列的所有文章都可以在这里查看http://blog.csdn.net/cloud_castle/article/category/2123873 接上文Qt5官方demo解析集28--Extend ...
- RobotFramework 官方demo Quick Start Guide rst配置文件分析
RobotFramework官方demo Quick Start Guide rst配置文件分析 by:授客 QQ:1033553122 博客:http://blog.sina.com.c ...
- RobotFramework RobotFramework官方demo Quick Start Guide浅析
RobotFramework官方demo Quick Start Guide浅析 by:授客 QQ:1033553122 博客:http://blog.sina.com.cn/ishouk ...
- dubbo系列四、dubbo服务暴露过程源码解析
一.代码准备 1.示例代码 参考dubbo系列二.dubbo+zookeeper+dubboadmin分布式服务框架搭建(windows平台) 2.简单了解下spring自定义标签 https://w ...
- Qt5官方demo解析集30——Extending QML - Binding Example
本系列全部文章能够在这里查看http://blog.csdn.net/cloud_castle/article/category/2123873 接上文Qt5官方demo解析集29--Extendin ...
- Qt5官方demo解析集13——Qt Quick Particles Examples - Image Particles
本系列全部文章能够在这里查看http://blog.csdn.net/cloud_castle/article/category/2123873 接上文 Qt5官方demo解析集12--Qt Quic ...
随机推荐
- Objective-C if语句处理 BOOL值不为1和0的情况
BOOL ,布尔值,在Objective-C ,BOOL类型被typedef为signed char(有符号的整型),YES被#define为1,NO被#define为0. 事实上,xcode的编译器 ...
- [No000049]狗日的中年——姜文
文件名 大小 [No000049]狗日的中年——姜文.7z 228KB
- [No000033]码农网-如何锻炼出最牛程序员的编码套路
最近,我大量阅读了Steve Yegge的文章.其中有一篇叫"Practicing Programming"(练习编程),写成于2005年,读后令我惊讶不已: 与你所相信的恰恰相反 ...
- Eclipse仿Visual AssistX 编辑着色插件
1. 风格下载 http://www.eclipsecolorthemes.org/?view=theme&id=4602 2. 风格的安装与卸载 http://www.cnblogs.com ...
- 备战NOIP每周写题记录(一)···不间断更新
※Recorded By ksq2013 //其实这段时间写的题远远大于这篇博文中的内容,只不过那些数以百记的基础题目实在没必要写在blog上; ※week one 2016.7.18 Monday ...
- 5.Transact-SQL编程
转载于:http://www.cnblogs.com/hoojo/archive/2011/07/19/2110862.html Transact-SQL中的存储过程,非常类似于Java语言中的方法, ...
- 修改linux的最大文件句柄数限制
在当前session有效,用户退出或者系统重新后恢复默认值 2)修改profile文件:在profile文件中添加:ulimit -n 65535 ...
- SuperSlidev2.1滑动门
1.引用jQuery.js 和 jquery.SuperSlide.js 因为SuperSlide是基于jQuery的插件,所以前提必须先引用jQuery,再引用SuperSlide <head ...
- How to regress out unwanted vectors
Source: http://stats.stackexchange.com/questions/117840/how-to-regress-out-some-variables Answer in ...
- js profiler
https://developers.google.com/web/fundamentals/performance/critical-rendering-path/?hl=en https://de ...