zookeeper dubbo-admin搭建

2018-09-08  本文已影响0人  KwongRay

1.1 zookeeper部署

    `# 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`

     |
image image

1.2 监控中心的安装配置


1.3 服务提供者和消费者:

image image
package com.renhq.dubbotest.provider;
 publicinterfaceService{
 String sayHello(String name);
 }
package com.renhq.dubbotest.providerIm;
import java.io.IOException;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.renhq.dubbotest.provider.Service;
publicclassServiceImimplementsService{
publicString sayHello(String name){
return"Hello "+ name;
}
publicstaticvoid main(String[] args)throwsIOException{
ClassPathXmlApplicationContext context =newClassPathXmlApplicationContext("provider.xml");
context.start();
System.in.read();
}
}
<?xml version="1.0" encoding="UTF-8"?>
<beansxmlns="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:applicationname="hello-world-provider"/>
<!-- 使用multicast广播注册中心暴露服务地址
<dubbo:registry address="multicast://224.5.6.7:1234" /> -->
<!-- 用dubbo协议在20880端口暴露服务 -->
<dubbo:protocolname="dubbo"port="20888"/>
<!-- 使用zookeeper注册中心暴露服务地址 -->
<dubbo:registryaddress="zookeeper://127.0.0.1:2181"/>
<!-- 声明需要暴露的服务接口 -->
<dubbo:serviceinterface="com.renhq.dubbotest.provider.Service"ref="demoService"/>
<!-- 和本地bean一样实现服务 -->
<beanid="demoService"class="com.renhq.dubbotest.providerIm.ServiceIm"/>
</beans>
package com.renhq.dubbotest.comsumer;
import java.io.IOException;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.renhq.dubbotest.provider.Service;
publicclassConsumer{
publicstaticvoid main(String[] args)throwsIOException{
ClassPathXmlApplicationContext context =newClassPathXmlApplicationContext("consumer.xml");
context.start();
// System.out.println("----------------nihao ----------------------"); // 显示调用结果
Service demoService =(Service) context.getBean("demoService");// 获取远程服务代理
String hello = demoService.sayHello("world");// 执行远程方法
System.out.println(hello);// 显示调用结果
System.in.read();
}
}
<?xml version="1.0" encoding="UTF-8"?>
<beansxmlns="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:applicationname="consumer-of-helloworld-app"/>
<!-- 使用multicast广播注册中心暴露发现服务地址 -->
<!-- <dubbo:registry address="multicast://224.5.6.7:1234" /> -->
<!-- 使用zookeeper注册中心暴露服务地址 -->
<dubbo:registryaddress="zookeeper://127.0.0.1:2181"/>
<!-- 生成远程服务代理,可以和本地bean一样使用demoService -->
<dubbo:referenceid="demoService"interface="com.renhq.dubbotest.provider.Service"/>
</beans>

provider.xml的配置:

     <dubbo:serviceinterface="com.renhq.dubbotest.provider.Service"ref="demoService"registry="N/A"/>

consumer.xml的配置:

     <dubbo:referenceid="demoService"interface="com.renhq.dubbotest.provider.Service" url="dubbo://192.168.1.103:20880/com.renhq.dubbotest.provider.Service"/>
image image
转自:https://www.cnblogs.com/renhq/p/4654925.html
上一篇 下一篇

猜你喜欢

热点阅读