based-on-zk-dubbo-demo.md

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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容