dubbo服务 && rpc

来源:互联网 发布:mac如何解压exe文件 编辑:程序博客网 时间:2024/06/08 02:11

官网:http://dubbo.io/


1.xml配置

(1)生产者:(下面该配置既是生产者也是消费者)

        

provider.xml
<?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"
       xmlns:context="http://www.springframework.org/schema/context"
       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
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
    <bean class="com.yiran.service.gin.api.GinApiApplicationContext" />


    <dubbo:application name="项目名字" organization="dubbox"/>
    <dubbo:registry address="${dubbo.registry.address}" />
    <dubbo:protocol name="dubbo" port="${dubbo.protocol.port}" />
    <!-- 扫描注解包路径,多个包用逗号分隔,不填pacakge表示扫描当前ApplicationContext中所有的类 -->
    <dubbo:annotation package="包名" />


    <dubbo:service interface="com.xxx.service.xxx.query.xxxService" ref="xxxServiceImpl" filter="Profiling">
        <dubbo:method name="queryGoodsList">
            <dubbo:argument index="1"/>
        </dubbo:method>
        <dubbo:method name="queryFavoriteGoodsInfoList"/>
        <dubbo:method name="queryMallRecGoodsInfo"/>
    </dubbo:service>


    <!-- 生成远程服务代理,可以和本地bean一样使用demoService -->
    <dubbo:reference id="xxxQueryService" interface="com.xxx.service.xxx.query.xxxQueryService" check="false">
    </dubbo:reference>
</beans>

(2)消费者:
consumer.xml
<?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"
       xmlns:context="http://www.springframework.org/schema/context"
       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
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
    <bean class="com.yiran.service.gin.api.GinApiApplicationContext" />


    <dubbo:application name="项目名字" organization="dubbox"/>
    <!-- dubbo 注册中心的地址 -->
    <dubbo:registry address="${dubbo.registry.address}" />



    <!-- 生成远程服务代理,可以和本地bean一样使用demoService -->
    <dubbo:reference id="xxxQueryService" interface="com.xxx.service.xxx.query.xxxQueryService" check="false">
    </dubbo:reference>
</beans>

2.注意事项:
(1)消费者和生产者的请求和返回格式一致;(生产者打jar包给消费者)
(2)request 和 response class 都需要序列化,并且response 需要有空的构造函数。(否则new response class时会报错)

3.telnet测试(序列化测不出来)

telnet localhost 20880(provider dubbo server port)

正常情况下,进入telnet窗口,键入回车进入dubbo命令模式。

ls 查看提供的服务

invoke com.xxx.service.xxx.query.xxxQueryService.dy({"goodsId":"10000","type":"2"})看返回结果


0 0