dubbo-一个简单地dubbo实例(附github地址)

# my-dubbo-demo1
1.The demo uses multicast as the registry since it is simple and does not require to extra installation
<dubbo:registry address="multicast://224.5.6.7:1234"/>
2.http://code.alibabatech.com/schema/dubbo这个地方和官网的不一样,因为使用的版本不同,需根据dubbo的jar包中的dubbo.xsd确定

来总结一下步骤:
1.三个模块,api 、provider、consumer

2.provider 、consumer都依赖api,provider实现api中的接口

3.provider暴露服务:
1.use multicast registry center to export service
2.use dubbo protocol to export service on port 20880
3.spring配置bean:<bean id="demoService" class="com.dr.service.DemoServiceImpl"/>实现接口的类
4.暴露服务接口:declare the service interface to be exported
<dubbo:service interface="com.dr.api.DemoService" ref="demoService"/>

4.service端的应用程序:加载spring配置,context.start(),阻塞程序,使得服务一直运行

5.消费端的应用程序:
1.编写spring配置文件:
use multicast registry center to discover service,
注册到zookeeper:<dubbo:registry address="multicast://224.5.6.7:1234"/>

generate proxy for the remote service
<dubbo:reference id="demoService" check="false" interface="com.dr.api.DemoService"/>

2.加载spring配置文件,启动,调用

gitHub地址:https://github.com/dengrongrong/my-dubbo-demo1

猜你喜欢

转载自www.cnblogs.com/dengrong/p/10977310.html