based-on-zk-dubbo-demo.md

dubbo-demo based-on zk registry center

  • zk cluster環(huán)境安裝不討論

  • dubbo-admin不討論

  • dubbo producer/consumer

    • producer
      • interface(這個(gè)接口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

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容