一、zookeeper配置中心安装

1、下载安装包,zookeeper-3.4.6.tar.gz

2、解压安装包,修改配置文件

参考zookeeper-3.4.6/conf/zoo_sample.cfg文件,同步录下建立zoo.cfg,配置如下:

# The number of milliseconds of each tick
tickTime=
# The number of ticks that the initial
# synchronization phase can take
initLimit=
# The number of ticks that can pass between
# sending a request and getting an acknowledgement
syncLimit=
# the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just
# example sakes.
dataDir=E:\项目\zookeeper-3.4.\data
# the port at which the clients will connect
clientPort=
# the maximum number of client connections.
# increase this if you need to handle more clients
#maxClientCnxns=
#
# 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=
# Purge task interval in hours
# Set to "" to disable auto purge feature
#autopurge.purgeInterval=

3、启动zk

点击E:\项目\zookeeper-3.4.6\bin\zkServer.cmd

socket connection from /192.168.1.100:

二、dubboadmin监控中心的安装配置(非必须)

1、下载tomcat安装运行

2、下载dubbo-admin-2.5.8.war到tomcat7 \ webapps目录下

3、修改dubbo.properties

重启tomcat、在编译后的文件中找到\WEB-INF文件夹下的dubbo.properties文件,然后进行配置,默认属性配置如下:

dubbo.registry.address=zookeeper://192.168.1.100:2181
dubbo.admin.root.password=root
dubbo.admin.guest.password=guest

4、验证dubbo-admin

重启zk、tomcat、访问:http://192.168.1.100:8080/dubbo-admin-2.5.8  ,进入监控中心的管理界面(默认管理员账户密码为:root,root)

三、dubbo代码示例

1、公共接口service

package com.dubbo.demo.api;

public interface DemoRpcService {

    /**
* 测试方法
* @return
*/
String getUserName(String uid);
}

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<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>dubbo.demo</groupId>
<artifactId>dubbo-api</artifactId>
<version>1.0-SNAPSHOT</version>
</project>

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();
}

dubbo-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应用程序命名-->
<dubbo:application name="dubbo-demo-provider"/> <!--dubbo注册地址-->
<dubbo:registry address="zookeeper://192.168.1.100:2181"/> <!--dubbo协议地址-->
<dubbo:protocol name="dubbo" port="20880"/> <!--接口声明-->
<dubbo:service interface="com.dubbo.demo.api.DemoRpcService" ref="demoRpcService"/>
<bean id="demoRpcService" class="com.dubbo.demo.DemoRpcServiceImpl"/>
</beans>

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<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>dubbo.demo</groupId>
<artifactId>dubbo-provider</artifactId>
<version>1.0-SNAPSHOT</version> <dependencies>
<!-- dubbo -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>dubbo</artifactId>
<version>2.6.0</version>
</dependency>
<!-- zookeeper客户端 -->
<dependency>
<groupId>com.101tec</groupId>
<artifactId>zkclient</artifactId>
<version>0.10</version>
</dependency>
<!-- api接口 -->
<dependency>
<groupId>dubbo.demo</groupId>
<artifactId>dubbo-api</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies> </project>

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();
}

dubbo-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应用程序命名-->
<dubbo:application name="dubbo-demo-provider"/> <!--dubbo注册地址-->
<dubbo:registry address="zookeeper://192.168.1.100:2181"/> <!--接口引用-->
<dubbo:reference interface="com.dubbo.demo.api.DemoRpcService" id="demoRpcService"/>
</beans>

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<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>dubbo.demo</groupId>
<artifactId>dubbo-consumer</artifactId>
<version>1.0-SNAPSHOT</version> <dependencies>
<!-- dubbo -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>dubbo</artifactId>
<version>2.6.0</version>
</dependency>
<!-- zookeeper客户端 -->
<dependency>
<groupId>com.101tec</groupId>
<artifactId>zkclient</artifactId>
<version>0.10</version>
</dependency>
<!-- api接口 -->
<dependency>
<groupId>dubbo.demo</groupId>
<artifactId>dubbo-api</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>utf-8</encoding>
</configuration>
</plugin>
</plugins>
</build> </project>

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、演示代码下载地址

GitHub:https://github.com/Star-Lordxing/dubbo-demo

dubbo系列二、dubbo+zookeeper+dubboadmin分布式服务框架搭建(windows平台)的更多相关文章

  1. 搭建dubbo+zookeeper+dubboadmin分布式服务框架(windows平台下)

    1.zookeeper注册中心的配置安装 1.1 下载zookeeper包(zookeeper-3.4.6.tar.gz),ZooKeeper是一个分布式的,开放源码的分布式应用程序协调服务,是Goo ...

  2. 【转帖】Dubbo:来自于阿里巴巴的分布式服务框架

    http://www.biaodianfu.com/dubbo.html Dubbo是阿里巴巴SOA服务化治理方案的核心框架,每天为2,000+个服务提供3,000,000,000+次访问量支持,并被 ...

  3. 【Zookeeper】分布式服务框架 Zookeeper -- 管理分布式环境中的数据

    Zookeeper 分布式服务框架是 Apache Hadoop 的一个子项目,它主要是用来解决分布式应用中经常遇到的一些数据管理问题,如:统一命名服务.状态同步服务.集群管理.分布式应用配置项的管理 ...

  4. kafka系列二:多节点分布式集群搭建

    上一篇分享了单节点伪分布式集群搭建方法,本篇来分享一下多节点分布式集群搭建方法.多节点分布式集群结构如下图所示: 为了方便查阅,本篇将和上一篇一样从零开始一步一步进行集群搭建. 一.安装Jdk 具体安 ...

  5. Dubbo阿里Alibaba开源的分布式服务框架

    [获奖公布]"我的2016"主题征文活动    程序猿全指南,让[移动开发]更简单!      [观点]移动原生App开发和HTML 5开发,你更看好哪个?   博客的神秘功能 D ...

  6. 阿里巴巴分布式服务框架Dubbo介绍(1)主要特色

    引言 互联网服务和BS架构的传统企业软件相比,系统规模上产生了量级的差距.例如 传统BS企业内部门户只需要考虑数百人以及几千人的访问压力,而大型互联网服务有时需要考虑的是千万甚至上亿的用户: 传统企业 ...

  7. Dubbo 分布式服务框架(spring、zookeeper)

    DUBBO DUBBO是一个分布式服务框架,致力于提供高性能和透明化的RPC远程服务调用方案,是阿里巴巴SOA服务化治理方案的核心框架, alibaba资源 源码:https://github.com ...

  8. Dubbo分布式服务框架入门

    参考http://blog.csdn.net/u013142781/article/details/50387583 一.Dubbo概念介绍 1.1.Dubbo是什么? Dubbo是一个分布式服务框架 ...

  9. Dubbo分布式服务框架入门使用

    概念: Provider 暴露服务方称之为"服务提供者". Consumer 调用远程服务方称之为"服务消费者". Registry 服务注册与发现的中心目录服 ...

随机推荐

  1. wireshark配合jmeter测试webservice接口

    1.首先,获取本地和接口的ip,以便设置过滤 2.wireshark设置过滤 ip.dst==192.168.0.101 and ip.src==61.147.124.120 and http 3.执 ...

  2. C# 随机四位数验证码

    string str ="abcdefghigklmnopqrstuvwxyzABCDEFJHIGKLMNOPQRSTUVWXYZ1234567890"; while(true){ ...

  3. c/c++ 整形转字符串

    int findex;char instr[10]; sprintf(instr,"%d",findex); 好像ltoa用不了...

  4. springboot整合freemarker

    前后端分离现在越来越多,如何有效的使用springboot来整合我们的页面是一个很重要的问题. springboot整合freemarker有以下几个步骤,也总结下我所犯的错误: 1.加依赖: 2.配 ...

  5. zabbix3.x添加H3C网络设备详解

    zabbix3.x添加H3C网络设备详解 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 前言: 欢迎加入:高级运维工程师之路 598432640 相信大家在看我的文章之前,也看过其 ...

  6. 函数和常用模块【day04】:内置函数(八)

    一.常用内置函数 1.表格 二.内置函数详情(1-10) 1.abs(x) 功能:取数的绝对值 1 2 >>> abs(-1)  #取-1的绝对值 1 2.all(iterable) ...

  7. Hive记录-Sqoop常用命令

    1.sqoop是什么 Sqoop是一款开源的数据迁移工具,主要用于Hadoop(Hive)与传统的关系型数据库(mysql...)相互之间的数据迁移. 2.sqoop的特点 sqoop的底层实现是ma ...

  8. liunx必知必会(2)

    一.SSH免密登陆配置 1.相关概念 SSH 为 Secure Shell(安全外壳协议) 的缩写. 很多ftp.pop和telnet在本质上都是不安全的,因为它们在网络上用明文传送口令和数据,别有用 ...

  9. 跳表,Redis 为什么用跳表而不用平衡树?

    https://juejin.im/post/57fa935b0e3dd90057c50fbc 在 Redis 中,list 有两种存储方式:双链表(LinkedList)和压缩双链表(ziplist ...

  10. 【JUC】JDK1.8源码分析之ReentrantReadWriteLock

    重入锁ReentrantLock是排他锁,排他锁在同一时刻仅有一个线程可以进行访问,但是在大多数场景下,大部分时间都是提供读服务,而写服务占有的时间较少.然而读服务不存在数据竞争问题,如果一个线程在读 ...