Dubbo zookeeper 初探
2015-03-25 00:00
337 查看
1.zookeeper http://zookeeper.apache.org/ 官网下载,然后安装
启动时,需要将 zoo_sample.cfg 改成 zoo.cfg
2. dubbo-demo-api 定义接口
3.dubbo-demo-provider 服务提供者
provider.xml配置
启动服务
引用jar
![](http://static.oschina.net/uploads/img/201503/25111525_AFGS.jpg)
3.dubbo-demo-consumer
consumer.xml
4.dubbo-admin
下载dubbo-admin项目,部署到tomcat6下面,启动tomcat ,在浏览器打开:http://localhost:8080/dubbo-admin, 输入用户名/密码:root/root
![](http://static.oschina.net/uploads/img/201503/25111525_21yB.jpg)
建议参考资料:
http://blog.csdn.net/lin_fs/article/details/7395307
http://blog.csdn.net/goliathray/article/details/8565801
http://zy116494718.iteye.com/blog/1830138
http://agapple.iteye.com/blog/1292473
http://www.open-open.com/news/view/1442a5c
http://code.alibabatech.com/wiki/display/dubbo/Home
http://code.alibabatech.com/wiki/display/dubbo/User+Guide-zh
工程下载路径:http://download.csdn.net/detail/wxwzy738/6553431
启动时,需要将 zoo_sample.cfg 改成 zoo.cfg
# 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=D:\\Zookeeper-3.4.5\\data # the port at which the clients will connect clientPort=2181 # # 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
2. dubbo-demo-api 定义接口
public interface IProcessData { public String deal(String data); }
3.dubbo-demo-provider 服务提供者
public class ProcessDataImpl implements IProcessData { /* * @see com.xxx.bubbo.provider.IProcessData#deal(java.lang.String) */ @Override public String deal(String data) { try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } return "Finished:" + data; } }
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 "> <!-- Application name --> <dubbo:application name="hello-world-app" /> <!-- registry address, used for service to register itself --> <dubbo:registry address="zookeeper://127.0.0.1:2181" /> <!-- expose this service through dubbo protocol, through port 20880 --> <!-- <dubbo:protocol name="dubbo" port="20880" /> <dubbo:protocol name="dubbo" port="9090" server="netty" client="netty" codec="dubbo" serialization="hessian2" charset="UTF-8" threadpool="fixed" threads="100" queues="0" iothreads="9" buffer="8192" accepts="1000" payload="8388608" /> --> <!-- Service interface Concurrent Control --> <dubbo:service interface="com.bestpay.dubbo.provider.IProcessData" ref="demoService" executes="10" /> <!-- Default Protocol --> <!-- <dubbo:protocol server="netty" /> --> <!-- designate implementation --> <bean id="demoService" class="com.xxx.dubbo.provider.ProcessDataImpl" /> </beans>
启动服务
public class DubboProviderMain { /** * @Title main * @Description TODO * @Author weizhi2018 * @param args * @throws */ public static void main(String[] args) throws Exception { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( new String[]{"provider.xml"}); context.start(); System.out.println("Press any key to exit."); System.in.read(); } }
引用jar
![](http://static.oschina.net/uploads/img/201503/25111525_AFGS.jpg)
3.dubbo-demo-consumer
public class ConsumerThd implements Runnable { /* * @see java.lang.Runnable#run() */ @Override public void run() { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( new String[]{"consumer.xml"}); context.start(); IProcessData demoService = (IProcessData) context.getBean("demoService"); // get // service // invocation // proxy String hello = demoService.deal("nihao"); // do invoke! System.out.println(Thread.currentThread().getName() + " "+hello); } }
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 "> <!-- consumer application name --> <dubbo:application name="consumer-of-helloworld-app" /> <!-- registry address, used for consumer to discover services --> <dubbo:registry address="zookeeper://127.0.0.1:2181" /> <dubbo:consumer timeout="5000"/> <!-- which service to consume? --> <dubbo:reference id="demoService" interface="com.xxx.dubbo.provider.IProcessData" /> </beans>
4.dubbo-admin
下载dubbo-admin项目,部署到tomcat6下面,启动tomcat ,在浏览器打开:http://localhost:8080/dubbo-admin, 输入用户名/密码:root/root
![](http://static.oschina.net/uploads/img/201503/25111525_21yB.jpg)
建议参考资料:
http://blog.csdn.net/lin_fs/article/details/7395307
http://blog.csdn.net/goliathray/article/details/8565801
http://zy116494718.iteye.com/blog/1830138
http://agapple.iteye.com/blog/1292473
http://www.open-open.com/news/view/1442a5c
http://code.alibabatech.com/wiki/display/dubbo/Home
http://code.alibabatech.com/wiki/display/dubbo/User+Guide-zh
工程下载路径:http://download.csdn.net/detail/wxwzy738/6553431
相关文章推荐
- Dubbo zookeeper 初探(1)
- dubbo初探二之简单搭建zookeeper注册中心
- Dubbo zookeeper 初探(2)
- Dubbo zookeeper 初探【转】
- Dubbo + Zookeeper入门初探
- Dubbo zookeeper 初探【转】
- Dubbo zookeeper 初探
- Dubbo框架初探【用Spring配置声明暴露服务(可以使用multicast广播注册中心暴露服务地址或者使用zookeeper注册中心暴露服务地址)、加载Spring配置,启动服务】
- Dubbo zookeeper 初探和安装
- Dubbo zookeeper 初探【转】
- Dubbo zookeeper 初探
- [置顶] 分布式系统初探-zookeeper&dubbo环境搭建
- Dubbo zookeeper 初探
- [置顶] 分布式系统初探-ssm整合zookeeper & dubbo
- Dubbo zookeeper 初探【转】
- dubbo zookeeper初探
- Maven Dubbo zookeeper 初探
- Dubbo zookeeper 初探
- Dubbo zookeeper 初探
- Dubbo zookeeper 初探【转】