美文网首页dubbo
based-on-zk-dubbo-demo.md

based-on-zk-dubbo-demo.md

作者: andersonoy | 来源:发表于2017-07-10 19:41 被阅读0次

dubbo-demo based-on zk registry center

  • zk cluster环境安装不讨论

  • dubbo-admin不讨论

  • dubbo producer/consumer

    • producer
      • interface(这个接口producer consumer都依赖)
        public interface DemoService { public void sayHello(); }
      • interface implementation
        public class DemoServiceImpl implements DemoService { public void sayHello() { System.out.println("hello 00!"); } }
      • config file
        <?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="hello-world-app-producer" /> <dubbo:registry protocol="zookeeper" address="zookeeper://172.16.30.206:2183?backup=172.16.30.206:2182,172.16.30.206:2184" /> <dubbo:protocol name="dubbo" port="20880" /> <dubbo:service interface="com.fpx.dubbo.DemoService" ref="demoService" /> <bean id="demoService" class="com.fpx.dubbo.DemoServiceImpl" /> </beans>
      • producer bootstrap
        public class DubboProviderDemo { public static void main(String[] args) throws InterruptedException { new ClassPathXmlApplicationContext(new String[]{"provider.xml" }); while (true) {} } }
    • consumer
      • config file
        <?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="consumer-of-helloworld-app" /> <dubbo:registry protocol="zookeeper" address="zookeeper://172.16.30.206:2183?backup=172.16.30.206:2182,172.16.30.206:2184" /> <dubbo:reference id="demoService" interface="com.fpx.dubbo.DemoService"/> </beans>
      • consumer bootstrap
        public class DubboComsumeDemo { public static void main(String[] args) throws InterruptedException { ApplicationContext factory = new ClassPathXmlApplicationContext(new String[] {"comsumer.xml"}); DemoService demoService = (DemoService)factory.getBean("demoService"); demoService.sayHello(); } }
  • References

相关文章

网友评论

    本文标题:based-on-zk-dubbo-demo.md

    本文链接:https://www.haomeiwen.com/subject/utuuhxtx.html