介绍
dubbo是阿里巴巴的开源RPC框架。阿里巴巴Dubbo实现的源码分析 这篇文章介绍的挺好的。对应的主页是 http://code.alibabatech.com/wiki/display/dubbo/Home 。看dubbo主要是想学习一下对应的ClassLoader的隔离机制。不过所有技术都总HelloWorld开始,那就mark一下吧。
正文
我是通过zk做服务集群管理的。所以如果要跑下面这个程序,需要自己搭一个zk集群
对应的接口
package demo.service; /** * User: zhenghui * Date: 14-1-13 * Time: 上午10:40 */ public interface DemoService { public void sayHello(); }
实现类
package demo.service; /** * User: zhenghui * Date: 14-1-13 * Time: 上午10:41 */ public class DemoServiceImpl implements DemoService { @Override public void sayHello() { System.out.println("hello 00!"); } }
provider.xml
<?xml version="1.0" encoding="UTF-8"?> <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.xsd http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd "> <dubbo:application name="hello-world-app" /> <dubbo:registry protocol="zookeeper" address="10.125.195.174:2181" /> <dubbo:protocol name="dubbo" port="20880" /> <dubbo:service interface="demo.service.DemoService" ref="demoService" /> <!-- 和本地bean一样实现服务 --> <bean id="demoService" class="demo.service.DemoServiceImpl" /> </beans>
import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; /** * User: zhenghui * Date: 14-1-13 * Time: 下午1:54 */ public class DubboProviderDemo { public static void main(String[] args) throws InterruptedException { new ClassPathXmlApplicationContext( new String[] {"demo/provider.xml"}); while (true){} } }
comsumer
<?xml version="1.0" encoding="UTF-8"?> <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.xsd http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd "> <!-- 消费方应用名,用于计算依赖关系,不是匹配条件,不要与提供方一样 --> <dubbo:application name="consumer-of-helloworld-app" /> <!-- 使用multicast广播注册中心暴露发现服务地址 --> <dubbo:registry protocol="zookeeper" address="10.125.195.174:2181" /> <!-- 生成远程服务代理,可以和本地bean一样使用demoService --> <dubbo:reference id="demoService" interface="demo.service.DemoService" /> </beans>
import demo.service.DemoService; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; /** * User: zhenghui * Date: 14-1-13 * Time: 下午1:54 */ public class DubboComsumeDemo { public static void main(String[] args) throws InterruptedException { ApplicationContext factory = new ClassPathXmlApplicationContext( new String[] {"demo/comsumer.xml"}); DemoService demoService = (DemoService) factory.getBean("demoService"); demoService.sayHello(); } }
先运行 DubboProviderDemo 然后再运行DubboComsumeDemo ,然后就可以看到在DubboProviderDemo的console中打印 “hello 00!”
后面我会继续介绍dubbo,计划下一篇内容是它是如何启动provider的。
相关推荐
dubbo入门helloworld例子,使用maven构建,下载后可以直接导入工程运行
在网上找了好多dubbo的例子, 发现都有些复杂。 于是自己用idea搭的demo例子 ,没有冗余的配置文件, 一切从简 , 一个简单的 hello world例子 ,希望对dubbo初学者有所帮助。
调用telnet命令invoke,例如invoke com.phpple.service.FooService.bar('hello,world')\n 。 您可以在以下位置找到telnet命令: 从套接字的响应中读取并进行解析。要求PHP安装composer require phpple/...
spring boot dubbo 远程调用,实现hello world 项目。
dubbo2 源码解读 1. 源码阅读路径 2. dubbo诞生的背景 3. dubbo架构简介 4. helloworld例子 5. 源文件概述 6. 核心机制分析 7. 集群、容错
这是《可伸缩服务架构框架与中间件》中dubbo部分的例子——HelloWorld。这本书对初学者不友好,讲解的不是很细致,有些必须配置也没有提及。小编的例子(dubbo+zookeeper+maven+Idea)对此进行了完善:...
该项目包含helloworld(快速入门)、web(ssh项目快速搭建)、aop(切面编程)、data-redis(redis缓存)、quartz(集群任务实现)、shiro(权限管理)、oauth2(四种认证模式)、shign(接口参数防篡改重放)、encoder(用户...
1个目标文件,JNDI的使用例子,有源代码,可以下载参考,JNDI的使用,初始化Context,它是连接JNDI树的起始点,查找你要的对象,打印找到的对象,关闭Context…… ftp文件传输 2个目标文件,FTP的目标是:(1)提高...
1个目标文件,JNDI的使用例子,有源代码,可以下载参考,JNDI的使用,初始化Context,它是连接JNDI树的起始点,查找你要的对象,打印找到的对象,关闭Context…… ftp文件传输 2个目标文件,FTP的目标是:(1)提高...