提交 dc1c9b90 编写于 作者: 武汉红喜's avatar 武汉红喜

服务分组

上级 64dd2443
......@@ -13,17 +13,25 @@ public class DemoConsumer {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[]{"META-INF/spring/dubbo-demo-consumer.xml"});
context.start();
// dubbo protocol
DemoService demoService = (DemoService) context.getBean("demoService"); // 获取远程服务代理
String hello = demoService.sayHello("dubbo"); // 执行远程方法
System.out.println(hello); // 显示调用结果
DemoService demoService2 = (DemoService) context.getBean("demoService2"); // 获取远程服务代理
String hello2 = demoService2.sayHello("hessian直连"); // 执行远程方法
System.out.println(hello2); // 显示调用结果
// hessian protocol 直连
DemoService demoService2 = (DemoService) context.getBean("demoService2");
String hello2 = demoService2.sayHello("hessian直连");
System.out.println(hello2);
DemoService demoService3 = (DemoService) context.getBean("demoService3"); // 获取远程服务代理
String hello3 = demoService3.sayHello("hessian"); // 执行远程方法
System.out.println(hello3); // 显示调用结果
// hessian protocol
DemoService demoService3 = (DemoService) context.getBean("demoService3");
String hello3 = demoService3.sayHello("hessian");
System.out.println(hello3);
// service group
DemoService demoService4 = (DemoService) context.getBean("demoService4");
String hello4 = demoService4.sayHello("group:new");
System.out.println(hello4);
}
......
......@@ -20,4 +20,6 @@
<dubbo:reference id="demoService3" interface="org.hongxi.whatsmars.dubbo.demo.api.DemoService" protocol="hessian" />
<dubbo:reference id="demoService4" group="new" interface="org.hongxi.whatsmars.dubbo.demo.api.DemoService" />
</beans>
\ No newline at end of file
/**
* Created by shenhongxi on 2017/6/21.
*/
package org.hongxi.whatsmars.dubbo.demo.provider;
import org.hongxi.whatsmars.dubbo.demo.api.DemoService;
import org.springframework.stereotype.Service;
@Service("demoService2")
public class DemoServiceImpl2 implements DemoService {
public String sayHello(String name) {
return "Hello " + name;
}
}
\ No newline at end of file
......@@ -26,5 +26,7 @@
<dubbo:service interface="org.hongxi.whatsmars.dubbo.demo.api.DemoService" ref="demoService"
timeout="500" /> <!-- 默认配了 protocol="dubbo,hessian" -->
<!-- 类似group的还有version="2.0.0" -->
<dubbo:service group="new" interface="org.hongxi.whatsmars.dubbo.demo.api.DemoService" ref="demoService2" />
</beans>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册