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 ...
随机推荐
- Apache 的搭建及vim的简单命令
一. vim 简单命令 pwd 当前路径 ls 当前路径所有目录 cd 目录地址 跳转到指定目录 /xxx 查找xxx x 删除当前字符 n 执行上一次查找 二.为什么使用apa ...
- MVC code first数据迁移 转
coptto:http://www.cnblogs.com/miro/p/4164076.html 本篇是相对独立的一篇,主要讲解不丢失数据进行数据库结构升级. 前面我们讲解EF功能时(见第三篇文章) ...
- 字符串截取函数substr()
substr(参数1,参数2[,参数3]); 该系统函数返回被截后的子字符串,它接受2个必选参数,参数1为要截取的字符串,参数2为截取的开始位置,参数3可选,表示截取长度. 例子:substr(&qu ...
- Python的高级特性10:无聊的@property
@property装饰器其实有点无聊,单独拿出来作为一个知识点其实没必要,尽管它可以将方法变成属性,让get和set方法更好用,但是,它破坏了python的简洁(不是代码的简洁而是指语法上). 下面来 ...
- delphi附带通用控件安装方法:
附带通用控件安装方法:----------基本安装1.对于单个控件,Componet-->install component..-->PAS或DCU文件-->install;2.对于 ...
- 使用Jquery向一个空白网页动态创建一个iframe,及嵌入页面,和向嵌入页面传参
[csharp] view plaincopyprint?using Microsoft.VisualBasic; using System; using System.Collections; us ...
- 花生壳动态IP域名解析之python自动提交公网IP
#!/usr/bin/env python import re import os import time import random ip_current = '' while True: myip ...
- C#.NET 大型通用信息化系统集成快速开发平台 4.0 版本 - 独立子系统管理员功能实现
1: 由于公司一次性要开发10多个子系统,每个子系统都需要有相关的业务部门进行对应.2: 若用集中式管理方式,每个业务部门人员变动,权限变动时,都需要早IT信息中心进行调整,影响工作效率.及时性.3: ...
- web学习第一章
web学习第一章 我是大概9月10日开始走上IT之路的,一开始学习了小段时间的自动化办公软件, 昨天我开始学习客户端网页编程,我了解什么是WEB,一些比较老古董的计算模式和发展历史,印象最让我深刻 ...
- 利用mybatis-generator自动生成代码
mybatis-generator有三种用法:命令行.eclipse插件.maven插件.个人觉得maven插件最方便,可以在eclipse/intellij idea等ide上可以通用. 下面是从官 ...