标签:
# The number of milliseconds of each tick//ZK中的一个时间单元2000ms
tickTime=2000
# The number of ticks that the initial
# synchronization phase can take//Leader允许Follower在initLimit时间内完成初始化工作。
initLimit=10
# The number of ticks that can pass between
# sending a request and getting an acknowledgement
syncLimit=5
# the directory where the snapshot is stored.\\就是把内存中的数据存储成快照文件snapshot的目录
dataDir=E:\\dubbo\\zookeeperB\\data
# the port at which the clients will connect
clientPort=2181
dubbo.registry.address=zookeeper://127.0.0.1:2181
dubbo.admin.root.password=root
dubbo.admin.guest.password=guest
1 package com.renhq.dubbotest.provider; 2 publicinterfaceService{ 3 String sayHello(String name); 4 }
1 package com.renhq.dubbotest.providerIm; 2 import java.io.IOException; 3 import org.springframework.context.support.ClassPathXmlApplicationContext; 4 import com.renhq.dubbotest.provider.Service; 5 publicclassServiceImimplementsService{ 6 publicString sayHello(String name){ 7 return"Hello "+ name; 8 } 9 publicstaticvoid main(String[] args)throwsIOException{ 10 ClassPathXmlApplicationContext context =newClassPathXmlApplicationContext("provider.xml"); 11 context.start(); 12 System.in.read(); 13 } 14 }
1 <?xml version="1.0" encoding="UTF-8"?> 2 <beansxmlns="http://www.springframework.org/schema/beans" 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 6 http://www.springframework.org/schema/beans/spring-beans.xsd 7 http://code.alibabatech.com/schema/dubbo 8 http://code.alibabatech.com/schema/dubbo/dubbo.xsd"> 9 <!-- 提供方应用信息,用于计算依赖关系 --> 10 <dubbo:applicationname="hello-world-provider"/> 11 <!-- 使用multicast广播注册中心暴露服务地址 12 <dubbo:registry address="multicast://224.5.6.7:1234" /> --> 13 <!-- 用dubbo协议在20880端口暴露服务 --> 14 <dubbo:protocolname="dubbo"port="20888"/> 15 <!-- 使用zookeeper注册中心暴露服务地址 --> 16 <dubbo:registryaddress="zookeeper://127.0.0.1:2181"/> 17 <!-- 声明需要暴露的服务接口 --> 18 <dubbo:serviceinterface="com.renhq.dubbotest.provider.Service"ref="demoService"/> 19 <!-- 和本地bean一样实现服务 --> 20 <beanid="demoService"class="com.renhq.dubbotest.providerIm.ServiceIm"/> 21 </beans>
1 package com.renhq.dubbotest.comsumer; 2 import java.io.IOException; 3 import java.util.Collections; 4 import java.util.HashMap; 5 import java.util.Map; 6 import org.springframework.context.support.ClassPathXmlApplicationContext; 7 import com.renhq.dubbotest.provider.Service; 8 publicclassConsumer{ 9 publicstaticvoid main(String[] args)throwsIOException{ 10 ClassPathXmlApplicationContext context =newClassPathXmlApplicationContext("consumer.xml"); 11 context.start(); 12 // System.out.println("----------------nihao ----------------------"); // 显示调用结果 13 Service demoService =(Service) context.getBean("demoService");// 获取远程服务代理 14 String hello = demoService.sayHello("world");// 执行远程方法 15 System.out.println(hello);// 显示调用结果 16 System.in.read(); 17 } 18 }
1 <?xml version="1.0" encoding="UTF-8"?> 2 <beansxmlns="http://www.springframework.org/schema/beans" 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 6 http://www.springframework.org/schema/beans/spring-beans.xsd 7 http://code.alibabatech.com/schema/dubbo 8 http://code.alibabatech.com/schema/dubbo/dubbo.xsd"> 9 <!-- 消费方应用名,用于计算依赖关系,不是匹配条件,不要与提供方一样 --> 10 <dubbo:applicationname="consumer-of-helloworld-app"/> 11 <!-- 使用multicast广播注册中心暴露发现服务地址 --> 12 <!-- <dubbo:registry address="multicast://224.5.6.7:1234" /> --> 13 <!-- 使用zookeeper注册中心暴露服务地址 --> 14 <dubbo:registryaddress="zookeeper://127.0.0.1:2181"/> 15 <!-- 生成远程服务代理,可以和本地bean一样使用demoService --> 16 <dubbo:referenceid="demoService"interface="com.renhq.dubbotest.provider.Service"/> 17 </beans>
<!--在没有注册中心,直接暴露提供者的情况下,即:-->
<dubbo:serviceinterface="com.renhq.dubbotest.provider.Service"ref="demoService"registry="N/A"/>
<!--直连引用服务:在没有注册中心,直连提供者的情况下-->
<dubbo:referenceid="demoService"interface="com.renhq.dubbotest.provider.Service"url="dubbo://192.168.1.103:20880/com.renhq.dubbotest.provider.Service"/>
dubbo+zookeeper+dubboadmin环境搭建
标签:
原文地址:http://www.cnblogs.com/renhq/p/4654925.html