2017年2月20日Dubbo远程调用服务框架部署
2017-02-20 00:00
363 查看
Registry可以用ZooKeeper实现
在Monitor里面安装Dubbo-monitor
在Provider端引入dubbo的依赖,使用spring配置注册中心和监控中心,并注册服务
<?xml version="1.0" encoding="UTF-8"?> <beans ......> <!-- Application name --> <dubbo:application name="hello-world-app" /> <!-- registry address, used for service to register itself --> <dubbo:registry address="multicast://224.5.6.7:1234" /> <!-- expose this service through dubbo protocol, through port 2 0 8 8 0 --> <dubbo:protocol name="dubbo" port="2 0 8 8 0" /> <!-- which service interface do we expose? --> <dubbo:service interface="com.alibaba.hello.api.HelloService" ref="helloService" /> <!-- designate implementation --> <bean id="helloService" class="com.alibaba.hello.impl.HelloServiceImpl" /> </beans>
然后用一个包含main函数的类启动这个配置文件
import org.springframework.context.support.ClassPathXmlApplicationContext; public class Provider { public static void main(String[] args) { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[] {"provider.xml"}); //启动成功,监听端口为2 0 8 8 0 System.in.read(); // 按任意键退出 } }
在Consumer端引入dubbo的依赖,使用spring配置注册中心和监控中心
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns=......> <!-- consumer application name --> <dubbo:application name="consumer-of-helloworld-app" /> <!-- registry address, used for consumer to discover services --> <dubbo:registry address="multicast://224.5.6.7:1234" /> <!-- which service to consume? --> <dubbo:reference id="helloService" interface="com.alibaba.hello.api.HelloService" /> </beans>
最后在客户端消费服务
import org.springframework.context.support.ClassPathXmlApplicationContext; import com.alibaba.hello.api.HelloService; public class Consumer { public static void main(String[] args) { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[] {"consumer.xml"}); HelloService helloService = (HelloService)context.getBean("helloService"); // get service invocation proxy String hello = helloService.sayHello("world"); // do invoke! System.out.println( hello ); // cool, how are you~ } }
相关文章推荐
- Dubbo远程调用服务框架原理与示例
- ClassNotFoundException, org.jboss.netty.channel.ChannelPipelineFactory 缺少jar包【远程调用dubbo分布式服务框架遇到的问题】
- Dubbo远程调用服务框架原理与示例
- Dubbo分布式远程服务调用框架(告别Web Service模式中的WSdl,以服务者与消费者的方式在dubbo上注册
- 当当网开源Dubbox,扩展Dubbo服务框架支持REST风格远程调用
- 远程服务调用 Dubbo分布式框架
- Dubbo远程调用服务框架原理与示例
- 当当网开源Dubbox,扩展Dubbo服务框架支持REST风格远程调用
- 基于开源Dubbo分布式RPC服务框架的部署整合
- alibaba远程调用框架dubbo原理
- 远程服务调用框架设计与实现
- alibaba远程调用框架dubbo原理
- 远程调用框架dubbo原理
- 远程服务调用框架设计与实现
- Dubbo使用解析及远程服务框架
- RPC框架/高性能远程同步调用框架/分布式服务框架
- 远程调用框架dubbo
- 远程调用框架dubbo
- alibaba远程调用框架dubbo原理
- alibaba远程调用框架dubbo原理