dubbo简单demo

zookeeper,可以集群,可以只安装一台

 

依赖dubbo jar,  zkclient等

发布服务

<?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.infinity.dubbo.DemoServiceImpl"/>

    <!-- 提供方应用信息,用于计算依赖关系 -->
    <dubbo:application name="xixi_provider"/>

    <!-- 使用multicast广播注册中心暴露服务地址
    <dubbo:registry address="multicast://224.5.6.7:1234" />-->

    <!-- 使用zookeeper注册中心暴露服务地址 -->
    <!--<dubbo:registry address="zookeeper://192.168.118.4:2181"/>-->
    <dubbo:registry protocol="zookeeper" address="127.0.0.1:2181"/>

    <!-- 用dubbo协议在20880端口暴露服务 -->
    <dubbo:protocol name="dubbo" port="20880"/>

    <!-- 声明需要暴露的服务接口 -->
    <dubbo:service interface="com.infinity.dubbo.DemoService" ref="demoService"/>
</beans>

使用服务

<?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="hehe_consumer"/>

    <!-- 使用zookeeper注册中心暴露服务地址 -->
    <!-- <dubbo:registry address="multicast://224.5.6.7:1234" /> -->
    <dubbo:registry address="zookeeper://127.0.0.1:2181"/>

    <!-- 生成远程服务代理,可以像使用本地bean一样使用demoService -->
    <dubbo:reference id="demoService"
                     interface="com.infinity.dubbo.DemoService"/>

</beans>

碰到的问题

1. xml有个字符串没有包裹在<>

2.DemoService类包的路径不一致

 

至此,可以注册服务,获取服务了

 

 

安装

posted on 2016-09-22 11:14  天娱邪神  阅读(155)  评论(0编辑  收藏  举报