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 ...
随机推荐
- ImageMagick Remote Command Execute
CVE ID: CVE-2016-3714 我挺纠结应该用中文写博客还是应该用英文写博客.英文吧作用挺明显的,可以锻炼自己的英语表达能力,但是可能会阻碍和一些英文不好的朋友交流. It's upset ...
- VS Code
VS Code VS Code(Visual Studio Code)是由微软研发的一款免费.开源的跨平台文本(代码)编辑器.几乎完美的编辑器. 官网:https://code.visualstudi ...
- java 28 - 7 JDK8的新特性 之 接口可以使用方法
JDK8的新特性: http://bbs.itcast.cn/thread-24398-1-1.html 其中之一:接口可以使用方法 interface Inter { //抽象方法 public a ...
- windows下使用 linux命令好办法
1. 安装下载 CygwinPortable一键安装包.7z 2. 把安装路径下/ [D:\cygwinportable\CygwinPortable\App\Cygwin\bin] 加到 Path ...
- Eclipse自动打开实现类原型的工具
http://eclipse-tools.sourceforge.net/implementors/ I always use this implementors plugin to find all ...
- javascript删除元素节点
1.删除元素父节点 function removeElement(_element){ var _parentElement = _element.parentNode; if(_parentElem ...
- PHP命令行模式
<?php error_reporting(E_ALL); header('Content-Type:text/plain;charset=utf-8'); interface CommandA ...
- Splay整理
伸展树(Splay Tree),也叫分裂树,是一种二叉排序树,它能在O(log n)内完成插入.查找和删除操作.(来自百科) 伸展树的操作主要是
- 解决ssh-connect-to-host-github-com-port-22-connection-timed-out
PC:~$ ssh git@github.com ssh: connect to host github.com port 22: Connection timed out 解决办法:(linux下) ...
- &11,散列表
#1,是什么? 散列表(Hash table,也叫哈希表),是根据关键码值(Key value)而直接进行访问的数据结构.也就是说,它通过把关键码值映射到表中一个位置来访问记录,以加快查找的速度.这个 ...