Dubbo是高性能, 基于java实现的开源RPC框架,使得应用可通过高性能的 RPC 实现服务的输出和输入功能,可以和 Spring框架无缝集成。
Dubbo是一款高性能、轻量级的开源Java RPC框架,它提供了三大核心能力:面向接口的远程方法调用,智能容错和负载均衡,以及服务自动注册和发现。
Remoting: 网络通信框架,实现了 sync-over-async 和request-response 消息机制
RPC: 一个远程过程调用的抽象,支持负载均衡、容灾和集群功能
Registry: 服务目录框架用于服务的注册和服务事件发布和订阅
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--> <!--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--> <!--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~ } } |
原文:https://www.cnblogs.com/jvStarBlog/p/11019504.html