1.dubbo:
使用Hessian的序列化协议,传输则是TCP协议,使用了高性能的NIO框架Netty
服务接口
1 public interface DemoService { 2 String sayHello(String name); 3 }
服务实现
1 public class DemoServiceImpl implements DemoService {
2 public String sayHello(String name) {
3 return "Hello " + name;
4 }
5 }
Configure service provider
The code snippet below shows how a dubbo service provider is configured with spring framework, which is recommended, however you could also use API configuration if it’s preferred.
1 <?xml version="1.0" encoding="UTF-8"?>
2
3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4 xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
5 xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
6
7
8
9
10
11
Start service provider
1 public class Provider {
2 public static void main(String[] args) throws Exception {
3 ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
4 new String[] {"META-INF/spring/dubbo-demo-provider.xml"});
5 context.start();
6 System.in.read(); // press any key to exit
7 }
8 }
Configure service consumer
1 <?xml version="1.0" encoding="UTF-8"?>
2
3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4 xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
5 xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
6
7
8
9
Run service consumer
1 public class Consumer {
2 public static void main(String[] args) throws Exception {
3 ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
4 new String[]{"META-INF/spring/dubbo-demo-consumer.xml"});
5 context.start();
6 DemoService demoService = (DemoService) context.getBean("demoService"); // obtain proxy object for remote invocation
7 String hello = demoService.sayHello("world"); // execute remote invocation
8 System.out.println(hello); // show the result
9 }
10 }
2.RMI
实现结构图