Dubbo 学习2 Dubbo-Admin及服务注册到Zookeeper
来源:互联网 发布:电子滚动屏幕软件 编辑:程序博客网 时间:2024/05/18 01:43
1. 需要先安装好zookeeper
安装启动zookeeper后,输入jps,看到输出:
2. 下载编译dubbo-admin
检出 https://github.com/alibaba/dubbo ,
整个项目编译。有的文章讲只编译dubbo-admin就可以,但我没成功。
如果编译失败,多试几次。我试了很多次才成功了。
cd dubbo-master/mvn install -Dmaven.test.skip=true
将生成的dubbo-admin-..*-SNAMPSHOT.war 部署到tomcat
3. 配置文件
部署后,修改WEB-INFO/dubbo.properties
dubbo.registry.address=zookeeper://127.0.0.1:2181 dubbo.admin.root.password=root dubbo.admin.guest.password=guest
4. 登陆系统
账号密码是root/root
代码
类似前一章的代码,只是服务注册方式不同
interface
DemoService
package com.alibaba.dubbo.demo;public interface DemoService { String sayHello(String name);}
生产者
Provider.java
package com.alibaba.dubbo.demo;import org.springframework.context.support.ClassPathXmlApplicationContext;public class Provider { public static void main(String[] args) throws Exception { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( new String[] { "dubbo-demo-provider.xml" }); context.start(); System.in.read(); }}
DemoServiceImpl
package com.alibaba.dubbo.demo.provider;import com.alibaba.dubbo.demo.DemoService;public class DemoServiceImpl implements DemoService { public String sayHello(String name) { return "Hello " + name; }}
dubbo-demo-provider.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="demo-provider"/> <bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor"/> <!-- <dubbo:registry address="multicast://224.5.6.7:1234"/> --> <dubbo:registry address="zookeeper://127.0.0.1:2181" /> <dubbo:protocol name="dubbo" port="20880"/> <!-- 向注册中心注册暴漏服务地址,注册服务 --> <dubbo:service interface="com.alibaba.dubbo.demo.DemoService" ref="demoService"/> <bean id="demoService" class="com.alibaba.dubbo.demo.provider.DemoServiceImpl"/></beans>
pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.cn.ali.dubbo.provider</groupId> <artifactId>com.cn.ali.dubbo.provider</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name>com.cn.ali.dubbo.provider</name> <url>http://maven.apache.org</url> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <dependencies> <dependency> <groupId>org.apache.zookeeper</groupId> <artifactId>zookeeper</artifactId> <version>3.4.6</version> </dependency> <dependency> <groupId>com.github.sgroschupf</groupId> <artifactId>zkclient</artifactId> <version>0.1</version> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> <dependency> <groupId>com.alibaba</groupId> <artifactId>dubbo</artifactId> <version>2.5.7</version> </dependency> </dependencies></project>
启动后,可以在dubbo admin-服务治理-服务,看到服务名称。
消费者
Consumer
package com.alibaba.dubbo.demo;import org.springframework.context.support.ClassPathXmlApplicationContext;public class Consumer { public static void main(String[] args) throws Exception { String s[] = System.getProperty("java.class.path").split(";"); for (String string : s) { System.out.println(string); } ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[] { "dubbo-demo-consumer.xml" }); context.start(); DemoService demoService = (DemoService) context.getBean("demoService"); // obtain proxy object for remote invocation String hello = demoService.sayHello("world"); // execute remote invocation System.out.println(hello); // show the result }}
dubbo-demo-consumer.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="demo-consumer"/> <!-- <dubbo:registry address="multicast://224.5.6.7:1234"/> --> <dubbo:registry address="zookeeper://127.0.0.1:2181" /> <!-- 向注册中心订阅服务 --> <dubbo:reference id="demoService" interface="com.alibaba.dubbo.demo.DemoService"/></beans>
pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.cn.ali.dubbo.consumer</groupId> <artifactId>com.cn.ali.dubbo.consumer</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name>com.cn.ali.dubbo.consumer</name> <url>http://maven.apache.org</url> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <dependencies> <dependency> <groupId>org.apache.zookeeper</groupId> <artifactId>zookeeper</artifactId> <version>3.4.6</version> </dependency> <dependency> <groupId>com.github.sgroschupf</groupId> <artifactId>zkclient</artifactId> <version>0.1</version> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> <dependency> <groupId>com.alibaba</groupId> <artifactId>dubbo</artifactId> <version>2.5.7</version> </dependency> </dependencies></project>
启动消费者,到dubbo-admin查看服务:
参考:
http://blog.csdn.net/evankaka/article/details/47858707
阅读全文
0 0
- Dubbo 学习2 Dubbo-Admin及服务注册到Zookeeper
- 部署dubbo-admin监控dubbo服务(以zookeeper为注册中心)
- dubbo向zookeeper注册服务
- dubbo学习总结-(2)dubbo+zookeeper注册中心
- Dubbo学习笔记:注册到zookeeper并实现远程调用
- 分布式服务框架DUBBO(二)搭建dubbo服务-zookeeper与dubbo-admin的安装
- Dubbo学习总结(3)——Dubbo-Admin管理平台和Zookeeper注册中心的搭建
- Dubbo学习总结(3)——Dubbo-Admin管理平台和Zookeeper注册中心的搭建
- Dubbo学习(二)服务注册
- Dubbo-Admin管理平台和Zookeeper注册中心的搭建
- Dubbo-Admin管理平台和Zookeeper注册中心的搭建
- Dubbo-Admin管理平台和Zookeeper注册中心的搭建
- Dubbo-Admin管理平台和Zookeeper注册中心的搭建
- Zookeeper注册中心和Dubbo-Admin管理平台的搭建
- Dubbo-Admin管理平台和Zookeeper注册中心的搭建
- Dubbo-Admin管理平台和Zookeeper注册中心的搭建
- Zookeeper注册中心和Dubbo-Admin管理平台的搭建
- Dubbo-Admin管理平台和Zookeeper注册中心的搭建
- "ssh-agent"失败,错误代码:-1:System.Exception: Unable to to start ...
- week2学习总结
- 浏览器兼容之meta标签
- elk的安装使用(一)
- React数据传递---context
- Dubbo 学习2 Dubbo-Admin及服务注册到Zookeeper
- java文件字符流
- json的作用:按规定格式保存js语言中的一组数据并转换为字符串(json是种特殊的容器,一般保存对象和数组数据(可以嵌套),并把它们装换为字符串在网络中传输?))
- 笔记 vue.js循环语句小结
- spring-boot介绍
- linux 解压目录下所有的zip文件 find 、xargs
- MVP基类,Retrofit,OkHttp拦截器,RxJava封装
- 关于eclipse中xml文件的注释快捷键
- STM32 HAL 库, 配置串口DMA接收及空闲中断