dubbo 测试理解demo

这里demo仅仅是为了了解dubbo的用法啦啦啦~~~

不知道咋说这个东西,无侵入式的代码,简直就是棒棒的,代码也敲的爽爽的

好了,话不多说了,上代码盛宴

前期准备,zookeeper这个我前面有介绍啦

没看的再看一下:http://blog.csdn.net/qq_14926283/article/details/79213271

Dubbo管理平台的搭建,这个最好要要搭一下啦

方便看效果噻:http://blog.csdn.net/qq_14926283/article/details/79213924

好放大招:

<?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
        ">
    <!-- 具体的实现bean -->
    <bean id="demoService"
          class="com.test.impl.DemoServiceImpl" />
    <bean id="yhService"
          class="com.test.impl.UserServiceImpl" />
    <!-- 提供方应用信息,用于计算依赖关系 -->
    <dubbo:application name="anyname_provider" />
    <!-- 使用zookeeper注册中心暴露服务地址 -->
    <dubbo:registry address="zookeeper://127.0.0.1:2181" />
    <!-- 用dubbo协议在20880端口暴露服务 -->
    <dubbo:protocol name="dubbo" port="20881" />
    <!-- 声明需要暴露的服务接口 -->
    <dubbo:service interface="com.test.Provider"
                   ref="demoService" />
    <dubbo:service interface="com.test.UserService"
                   ref="yhService" />
</beans>

直接就拿出来看看,原理就是直接写service到zookeeper注册,这里接口就暴露啦,这里是提供者端的,然后我们来看看消费者端

<?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_app" />


    <dubbo:registry address="zookeeper://127.0.0.1:2181" />
    <dubbo:consumer timeout="5000" />


    <dubbo:reference id="demoService"
                     interface="com.test.Provider" />
    <dubbo:reference id="yhService"
                     interface="com.test.UserService" />
</beans>

这里是(reference)指向zookeeper的暴露的service接口,把我们本地的 interface="com.test.Provider"指过去,完美串接起来了


具体demo请看这里吧,下载链接:http://download.csdn.net/download/qq_14926283/10257524


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

斗码士

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值