Dubbo 是阿里巴巴公司开源的一个高性能优秀的服务框架,使得应用可通过高性能的 RPC 实现服务的输出和输入功能,可以和 Spring 框架无缝集成。
(1) 连通性:
(2) 健状性:
(3) 伸缩性:
定义一个Service Interface:( HelloService.Java )
package com.alibaba.hello.api;
public interface HelloService{
String sayHello(String name);
}
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>
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~
}
}
原文:http://www.cnblogs.com/xiangyh-blog/p/6388720.html