dubbo系列二、dubbo+zookeeper+dubboadmin分布式服务框架搭建(windows平台)
2021-07-09 01:08
标签:demo alt 安装 http conf 配置 lease 分享图片 guid 参考zookeeper-3.4.6/conf/zoo_sample.cfg文件,同步录下建立zoo.cfg,配置如下: 点击E:\项目\zookeeper-3.4.6\bin\zkServer.cmd 重启tomcat、在编译后的文件中找到\WEB-INF文件夹下的dubbo.properties文件,然后进行配置,默认属性配置如下: 重启zk、tomcat、访问:http://192.168.1.100:8080/dubbo-admin-2.5.8 ,进入监控中心的管理界面(默认管理员账户密码为:root,root) pom.xml 启动代码: dubbo-provider.xml pom.xml dubbo-consumer.xml: pom.xml 先启动生产者、再启动消费者 GitHub dubbo系列二、dubbo+zookeeper+dubboadmin分布式服务框架搭建(windows平台) 标签:demo alt 安装 http conf 配置 lease 分享图片 guid 原文地址:https://www.cnblogs.com/wangzhuxing/p/9723236.html一、zookeeper配置中心安装
1、下载安装包,zookeeper-3.4.6.tar.gz
2、解压安装包,修改配置文件
# The number of milliseconds of each tick
tickTime=2000
# The number of ticks that the initial
# synchronization phase can take
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.
# do not use /tmp for storage, /tmp here is just
# example sakes.
dataDir=E:\项目\zookeeper-3.4.6\data
# the port at which the clients will connect
clientPort=2181
# the maximum number of client connections.
# increase this if you need to handle more clients
#maxClientCnxns=60
#
# Be sure to read the maintenance section of the
# administrator guide before turning on autopurge.
#
# http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
#
# The number of snapshots to retain in dataDir
#autopurge.snapRetainCount=3
# Purge task interval in hours
# Set to "0" to disable auto purge feature
#autopurge.purgeInterval=1
3、启动zk
socket connection from /192.168.1.100:54836
二、dubboadmin监控中心的安装配置
1、下载tomcat安装运行
2、下载dubbo-admin-2.5.8.war到tomcat7 \ webapps目录下
3、修改dubbo.properties
dubbo.registry.address=zookeeper://192.168.1.100:2181
dubbo.admin.root.password=root
dubbo.admin.guest.password=guest
4、验证dubbo-admin
三、dubbo代码示例
1、公共接口service
package com.dubbo.demo.api;
public interface DemoRpcService {
/**
* 测试方法
* @return
*/
String getUserName(String uid);
}
2、生产者代码
package com.dubbo.demo;
import com.dubbo.demo.api.DemoRpcService;
public class DemoRpcServiceImpl implements DemoRpcService {
public String getUserName(String uid) {
System.out.println("接收入参:"+uid);
return "小明";
}
}
public static void main(String[] args) throws IOException {
ClassPathXmlApplicationContext context
= new ClassPathXmlApplicationContext("classpath:dubbo-provider.xml");
context.start();
// 阻塞当前进程,否则程序会直接停止
System.in.read();
}
3、消费者代码
public static void main(String[] args) throws IOException {
ClassPathXmlApplicationContext context
= new ClassPathXmlApplicationContext("classpath:dubbo-consumer.xml");
context.start();
String useId = "123456";
DemoRpcService demoService = (DemoRpcService) context.getBean("demoRpcService");
System.out.println("收到结果"+demoService.getUserName(useId));
// 阻塞当前进程,否则程序会直接停止
System.in.read();
}4、运行测试
Connected to the target VM, address: ‘127.0.0.1:52472‘, transport: ‘socket‘
log4j:WARN No appenders could be found for logger (org.springframework.core.env.StandardEnvironment).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
接收入参:123456
log4j:WARN No appenders could be found for logger (org.springframework.core.env.StandardEnvironment).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
收到结果小明
5、代码下载地址
文章标题:dubbo系列二、dubbo+zookeeper+dubboadmin分布式服务框架搭建(windows平台)
文章链接:http://soscw.com/essay/102563.html