2017年2月20日Dubbo远程调用服务框架部署

144202_fYKU_438393.png

Registry可以用ZooKeeper实现

在Monitor里面安装Dubbo-monitor

在Provider端引入dubbo的依赖,使用spring配置注册中心和监控中心,并注册服务

<?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>

然后用一个包含main函数的类启动这个配置文件

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(); // 按任意键退出
  }
}

在Consumer端引入dubbo的依赖,使用spring配置注册中心和监控中心

<?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~
  }
}

 

转载于:https://my.oschina.net/u/438393/blog/842083

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值