Dubbo远程调用服务框架原理与示例 - 沐风山
来源:互联网 发布:淘宝代充话费 编辑:程序博客网 时间:2024/05/08 21:25
Dubbo 是阿里巴巴公司开源的一个高性能优秀的服务框架,使得应用可通过高性能的 RPC 实现服务的输出和输入功能,可以和 Spring 框架无缝集成。 主要核心部件:
- Remoting: 网络通信框架,实现了 sync-over-async 和 request-response 消息机制.
- RPC: (Remote Procedure Call Protocol远程过程调用协议), 一个远程过程调用的抽象,支持负载均衡、容灾和集群功能
- Registry: 服务目录框架用于服务的注册和服务事件发布和订阅
Dubbo工作原理
- Provider
- 暴露服务方称之为“服务提供者”。
- Consumer
- 调用远程服务方称之为“服务消费者”。
- Registry
- 服务注册与发现的中心目录服务称之为“服务注册中心”。
- Monitor
- 统计服务的调用次调和调用时间的日志服务称之为“服务监控中心”。
例子 服务端
定义一个Service Interface:( HelloService.java )
package com.alibaba.hello.api;public interface HelloService{ String sayHello(String name);}
接口的实现类:( HelloServiceImpl.java )
package com.alibaba.hello.impl;import com.alibaba.hello.api.HelloService;public class HelloServiceImpl implements HelloService{ public String sayHello(String name){ return "Hello " + name; }}
Spring配置:( provider.xml )<?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>
测试代码:( Provider.java )
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(); // 按任意键退出 }}
客户端
Spring配置文件:( consumer.xml )
<?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>
客户端测试代码:( Consumer.java )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~ }}
0 0
- Dubbo远程调用服务框架原理与示例 - 沐风山
- Dubbo远程调用服务框架原理与示例
- Dubbo远程调用服务框架原理与示例
- 远程服务调用 Dubbo分布式框架
- alibaba远程调用框架dubbo原理
- alibaba远程调用框架dubbo原理
- alibaba远程调用框架dubbo原理
- alibaba远程调用框架dubbo原理
- alibaba远程调用框架dubbo原理
- alibaba远程调用框架dubbo原理
- 远程调用框架dubbo
- 远程调用框架dubbo
- 远程调用框架dubbo
- 远程调用框架dubbo
- Dubbo服务框架原理
- dubbo --- 一个远程服务调用的分布式框架
- dubbo 远程服务无法调用
- dubbo 远程服务调用流程
- Hibernate搭建学习
- 解决 DOS下cmd命令界面 内容不能完全显示问题
- 关于php资料免费分享
- Applause,用低科技手段解决高科技问题的众包测试团
- 异型链表
- Dubbo远程调用服务框架原理与示例 - 沐风山
- 同时支持手机号、用户名、邮箱登录
- HTTP 协议详解
- 行业发展的方向是哪里?
- 630说明解析
- poj1002 487-3279(哈希)
- 走近WSH
- 三极管的电平转换及驱动电路分析
- centos 查看版本