博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
(阿里巴巴 dubbo,有数据库,可执行 )dubbo zookeeper spring demo
阅读量:7076 次
发布时间:2019-06-28

本文共 4737 字,大约阅读时间需要 15 分钟。

源码下载  

  

windows zookeeper 下载地址 http://mirrors.tuna.tsinghua.edu.cn/apache/zookeeper/zookeeper-3.4.6/修改zookeeper配置文件zoo-example.cfg改为zoo.cfg,zookeeper默认寻找zoo.cfg配置文件# The number of milliseconds of each ticktickTime=2000# The number of ticks that the initial # synchronization phase can takeinitLimit=10# The number of ticks that can pass between # sending a request and getting an acknowledgementsyncLimit=5# the directory where the snapshot is stored.# do not use /tmp for storage, /tmp here is just # example sakes.#dataDir=/tmp/zookeeperdataDir=F:\\log\\zookeeper\\data  dataLogDir=F:\\log\\zookeeper\\log# the port at which the clients will connectclientPort=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启动zookeeperWindow下命令:进入bin目录 ->zkServer.cmd

 

 

配置  <dubbo:registry  id="zk1" address="quickstart.cloudera:2181" protocol="zookeeper" />

测试成功

 

 

  ,provider 发布 后 ,linux 下 zookeeper  path 会增加。 zookeeper 起到 注册中心,服务发现的作用

 
consumer 测试结果:
 

 

provider 发布,(这是一种发布方式)

 

 

 applictionContext-dubbo-provider.xml

  

 applictionContext.xml

 

 

 

package com.baoy.service;import java.util.List;import com.baoy.bean.User;/** * @author baoyou E-mail:curiousby@163.com * @version 2016年2月22日 上午10:24:23 * * desc: ... */public interface UserService {	public List
getAllUsers(); public void delUserById(int userId); public User getUserById(int userId); public void updateUser(User user); public void addUser(User user);}

 

 

 

package com.baoy.service.impl;import java.util.List;import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import com.baoy.bean.User;import com.baoy.dao.UserDao;import com.baoy.service.UserService;/** * @author baoyou E-mail:curiousby@163.com * @version 2016年2月22日 上午10:24:54 * * desc: ... */@Componentpublic class UserServiceImpl implements UserService {	@Autowired	UserDao userDao;				public List
getAllUsers() { return userDao.getAllUsers(); } public void delUserById(int userId) { userDao.delUserById(userId); } public User getUserById(int userId) { return userDao.getUserById(userId); } public void updateUser(User user) { userDao.updateUser(user); } public void addUser(User user) { userDao.addUser(user); }}

 

 provider 发布,上面有一种发布方式

package com.baoy.main;import java.io.IOException;import org.springframework.context.support.ClassPathXmlApplicationContext;/** * @author baoyou E-mail:curiousby@163.com * @version 2016年2月22日 下午4:44:44 * *          desc: ... */public class Start {	public static void main(String[] args) throws IOException {		ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(				new String[] { "classpath*:META-INF/spring/applictionContext.xml",						"classpath*:META-INF/spring/applictionContext-dubbo-provider.xml" });		context.start();		System.in.read(); // 按任意键退出	}}

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 appliction-dubbo-consumer.xml

 

 appliction.xml

 

 

package com.baoy.test; import java.util.List;import javax.annotation.Resource;import org.junit.Test;import org.junit.runner.RunWith;import org.springframework.test.context.ContextConfiguration;import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;import com.baoy.bean.User;import com.baoy.service.UserService;/** * @author baoyou E-mail:curiousby@163.com * @version 2016年2月22日 下午1:48:37 * * desc: ... */@RunWith(SpringJUnit4ClassRunner.class)@ContextConfiguration(locations = {"classpath:appliction.xml","classpath:appliction-dubbo-consumer.xml"})public class ConsumerTest {	 @Resource	UserService userService; 		@Test	public  void allUsersTest() { 		 List
allUsers = userService.getAllUsers(); System.out.println("\r\n\r\n\r\n"+allUsers.toString()+"\r\n\r\n\r\n"); } }

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

捐助开发者

在兴趣的驱动下,写一个免费的东西,有欣喜,也还有汗水,希望你喜欢我的作品,同时也能支持一下。 当然,有钱捧个钱场(右上角的爱心标志,支持支付宝和PayPal捐助),没钱捧个人场,谢谢各位。

 
 
 谢谢您的赞助,我会做的更好!

 

 

转载地址:http://ghcml.baihongyu.com/

你可能感兴趣的文章
265. Paint House II
查看>>
influxdb基本操作
查看>>
GDB 自动化操作的技术
查看>>
静态路由和策略路由的配置实践
查看>>
瀑布流之实例进阶
查看>>
听飞狐聊JavaScript设计模式系列13
查看>>
Future 模式
查看>>
Ruby on Rails 曝路径穿越与任意文件读取漏洞
查看>>
el-admin v1.6 发布,后台管理系统
查看>>
Boyer-Moore 算法
查看>>
让这世界再多一份 GNU m4 教程 (2)
查看>>
程序员最核心的竞争力是什么?
查看>>
java B2B2C 源码 Springcloud多租户电子商城系统-Consul整体架构 ...
查看>>
2017-11-27 对中文语法的编程语言的质疑与回应
查看>>
高瓴资本向好未来注入5亿美元股权投资
查看>>
无人零售技术解决商云拿科技获A+轮融资,英特尔投资领投 ...
查看>>
三篇文章了解TiDB技术内幕-说存储
查看>>
联想创投子公司国民认证,助力农行全面升级FIDO移动生物识别安全认证 ...
查看>>
技术:搭建私有云kodexplorer
查看>>
Java 面试之技术框架
查看>>