duboo入门

  1. 先搭建zookeeper环境

    下载Zookeeper-3.4.6.tar.gz  地址http://www.apache.org/dist/zookeeper/

    然后解压: 然后在对应的zookeeper-3.4.6/conf 下有一个文件zoo_sample.cfg的这个文件里面配置了监听客户端连接的端口等一些信息,Zookeeper 在启动时会找zoo.cfg这个文件作为默认配置文件,所以我们复制一个名称为zoo.cfg的文件

    修改里面配置为:
    # The number of milliseconds of each tick
    tickTime=2000
    # The number of ticks that the initial
    initLimit=10
    # The number of ticks that can pass between
    syncLimit=5
    # the directory where the snapshot is stored.
    dataDir=D://tools//zookeeper//tmp
    dataLogDir=D://tools//zookeeper//logs
    # the port at which the clients will connect
    clientPort=2181
    #autopurge.snapRetainCount=3
    # Set to "0" to disable auto purge feature
    #autopurge.purgeInterval=1
    然后启动zookeeper  在安装目录的bin目录下 zkServer.cmd

  2. 编写duboo简单demo

    代码目录如下:

    202957_oY8S_582886.png

    client

    package duboo.client;
    
    import org.springframework.context.support.ClassPathXmlApplicationContext;
    
    import cn.HelloWorld;
    
    public class ConsumerThd implements Runnable {
        public void run() {
            ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
                    new String[] { "applicationConsumer.xml" });
            context.start();
            HelloWorld helloWorld = (HelloWorld) context.getBean("demoService");
            String hello = helloWorld.hello("duboo");
            System.out.println(hello);
        }
    
        public static void main(String[] args) {
            new Thread(new ConsumerThd()).start();
        }
    }

    server

  3. package cn;
    
    /**
     * Created by zhouq on 2016/3/21.
     */
    public interface HelloWorld {
    
        public String hello(String name);
    }
  4. package cn.impl;
    
    import cn.HelloWorld;
    
    public class HelloWorldImpl implements HelloWorld {
        public String hello(String name) {
    
            return "hello" + name;
        }
    }
  5. package cn;
    
    import java.io.IOException;
    import org.springframework.context.support.ClassPathXmlApplicationContext;
    
    
    public class DubboProviderMain {
        public static void main(String[] args) throws IOException {
    
            ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
                    new String[] { "applicationProvider.xml" });
            context.start();
            System.out.println("Press any key to exit.");
            System.in.read();
        }
    }
  6. 配置文件:
  7. applicationConsumer.xml
  8. <?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:application name="duboo-client" />  
      <dubbo:registry address="zookeeper://127.0.0.1:2181"/>  
      <dubbo:reference   version="1.0"  id="demoService" interface="cn.HelloWorld"/>                                  
    </beans>
  9. applicationProvider.xml
  10. <?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:application name="duboo-server" /><!-- 注册地址 -->
        <dubbo:registry address="zookeeper://127.0.0.1:2181" />
        <dubbo:protocol name="dubbo" port="20880" />
        <dubbo:service version="1.0" interface="cn.HelloWorld"
            ref="demoService" executes="10" />
        <bean id="demoService" class="cn.impl.HelloWorldImpl" />
    </beans>

转载于:https://my.oschina.net/u/582886/blog/646226

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值