Dubbo是阿里巴巴公司开源的一个高性能优秀的服务框架,使得应用可通过高性能的 RPC 实现服务的输出和输入功能,可以和Spring框架无缝集成。
Remoting: 网络通信框架,实现了 sync-over-async 和 request-response 消息机制.
RPC: 一个远程过程调用的抽象,支持负载均衡、容灾和集群功能
Registry: 服务目录框架用于服务的注册和服务事件发布和订阅

Provider
|
1
2
3
4
5
6
7
8
|
package com.alibaba.hello.api;public interface HelloService{ String sayHello(String name);} |
|
1
2
3
4
5
6
7
|
package com.alibaba.hello.impl;import com.alibaba.hello.api.HelloService;public class HelloServiceImpl implements HelloService{ public String sayHello(String name){ return "Hello" + name; }} |
|
1
2
3
4
5
6
7
8
9
10
11
12
13
|
<?xmlversion="1.0"encoding="UTF-8"?><beans......> <!--Applicationname--> <dubbo:applicationname="hello-world-app"/> <!--registryaddress,usedforservicetoregisteritself--> <dubbo:registryaddress="multicast://224.5.6.7:1234"/> <!--exposethisservicethroughdubboprotocol,throughport20880--> <dubbo:protocolname="dubbo"port="20880"/> <!--whichserviceinterfacedoweexpose?--> <dubbo:serviceinterface="com.alibaba.hello.api.HelloService"ref="helloService"/> <!--designateimplementation--> <beanid="helloService"class="com.alibaba.hello.impl.HelloServiceImpl"/></beans> |
|
1
2
3
4
5
6
7
|
importorg.springframework.context.support.ClassPathXmlApplicationContext;public class Provider{ public static void main(String[] args){ ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(newString[]{"provider.xml"}); //启动成功,监听端口为20880System.in.read();//按任意键退出 }} |
|
1
2
3
4
5
6
7
8
9
|
<?xmlversion="1.0"encoding="UTF-8"?><beans xmlns=......> <!--consumerapplicationname--> <dubbo:applicationname="consumer-of-helloworld-app"/> <!--registryaddress,usedforconsumertodiscoverservices--> <dubbo:registryaddress="multicast://224.5.6.7:1234"/> <!--whichservicetoconsume?--> <dubbo:referenceid="helloService"interface="com.alibaba.hello.api.HelloService"/></beans> |
|
1
2
3
4
5
6
7
8
9
10
11
|
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(newString[]{"consumer.xml"}); HelloService helloService = (HelloService)context.getBean("helloService"); //getserviceinvocationproxyStringhello=helloService.sayHello("world"); //doinvoke!System.out.println(hello); //cool,howareyou~ }} |