码迷,mamicode.com
首页 > 其他好文 > 详细

基于dubbo2.5.5+zookeeper3.4.9的服务搭建

时间:2017-09-14 18:57:50      阅读:264      评论:0      收藏:0      [点我收藏+]

标签:reference   启动   java   color   用户名   img   admin   swagger   odi   

参考资料:https://segmentfault.com/a/1190000009568509
https://segmentfault.com/a/1190000004654903

0. 环境

Java: jdk1.8.0_144

OS: Windows 10(宿主机192.168.1.105)/Ubuntu 15.10(虚拟机192.168.1.21)

Tomcat: apache-tomcat-7.0.68

1. 下载zookeeper部署到虚拟机

  • 下载:`wget http://www.apache.org/dist/zookeeper/zookeeper-3.4.9/zookeeper-3.4.9.tar.gz`
  • 解压:`tar -zxvf zookeeper-3.4.9.tar.gz`
  • 配置zookeeper:`mv /usr/zookeeper-3.4.9/conf/zoo_sample.cfg /usr/zookeeper-3.4.9/conf/zoo.cfg`
  • 启动:在/usr/zookeeper-3.4.9/bin目录下执行`./zkServer.sh start`

2. 下载dubbo源码后打包dubbo-admin并部署到虚拟机

  • git下载dubbo源码:https://github.com/alibaba/dubbo/tree/dubbo-2.5.5
  • 修改dubbo-admin/src/main/webapp/WEB-INF/dubbo.properties文件的注册地址:dubbo.registry.address=zookeeper://192.168.1.21:2181
  • 打包生成war文件并部署到虚拟机(注意:需要隐藏项目名,否则内部跳转易出错)
  • 启动tomcat后访问http://192.168.1.21:8080/,用户名密码:root

技术分享

 

 

3. 创建项目并完成配置

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
  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 ">
  <dubbo:application name="dubbo-demo-provider" />
  <!-- zookeeper注册中心 -->
  <dubbo:registry address="zookeeper://192.168.1.21:2181" />
  <dubbo:protocol name="dubbo" port="20880" />

  <!-- 和本地bean一样实现服务 -->
  <bean id="demoService1" class="org.lxp.dubbo.service.DemoServiceImpl" />
  <bean id="demoService2" class="org.lxp.dubbo.service.DemoServiceImpl2" />

  <!-- 向注册中心注册暴漏服务地址,注册服务 -->
  <dubbo:service interface="org.lxp.dubbo.service.DemoService" ref="demoService1" executes="10" version="1.0.1" />
  <dubbo:service interface="org.lxp.dubbo.service.DemoService" ref="demoService2" executes="10" version="1.0.2" />

</beans>
  • 消费服务与zookeeper的连接配置applicationConsumer.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
  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">
  <dubbo:application name="dubbo-demo-consumer" />

  <dubbo:registry address="zookeeper://192.168.1.21:2181" />

  <!-- 向注册中心订阅服务 -->
  <dubbo:reference id="demoService1" interface="org.lxp.dubbo.service.DemoService" version="1.0.1" />
  <dubbo:reference id="demoService2" interface="org.lxp.dubbo.service.DemoService" version="1.0.2" />
</beans> 

4. 启动发布服务

  • 运行dubbo-demo-provider模块BootStrap类的main方法

技术分享

  • 服务已注册成功,见http://192.168.1.21:8080/governance/services

技术分享

5. 启动消费服务并测试

  • tomcat7-maven-plugin插件运行dubbo-demo-consumer应用成功后,可以见到消费者已注册

技术分享

  • 访问http://192.168.1.105:8080/dubbo-consumer/swagger-ui.html可测试API

技术分享

 

技术分享

 

基于dubbo2.5.5+zookeeper3.4.9的服务搭建

标签:reference   启动   java   color   用户名   img   admin   swagger   odi   

原文地址:http://www.cnblogs.com/hiver/p/7521522.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!