dubbo 直連不經過註冊中心

1.背景:現有springcloud項目已使用的註冊中心,並不想再使用zk作爲註冊中心,內部不同集羣(不在同一個註冊中心的集羣)直接的交互無法使用springcloud的feign 調用,直接發送Http不方便,最終決定使用Dubbo

2.springboot 集成dubbo,使用配置文件的方式

dubbo-customer.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"
       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="springboot-consumer"/>
    <!-- 集羣下url可疑指定多個逗號分隔例如:dubbo://127.0.0.1:20880,dubbo://127.0.0.1:20881 -->
    <dubbo:reference id="testService" version="1.0.0"  interface="com.yyf.dubbo.inf.TestService" url="dubbo://127.0.0.1:20880"/>
</beans>

springboot 啓動類上加上@ImportResource(value = {"classpath:dubbo-customer.xml"})

dubbo-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"
       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="springboot-provider" />
    <dubbo:annotation package="com.yyf.dubbo.provider.service"></dubbo:annotation>
    <dubbo:protocol name="${dubbo.name}" port="${dubbo.port}"></dubbo:protocol>
    <!-- 棄用註冊中心 -->
    <dubbo:registry address="N/A" />
    <dubbo:service  ref="testServiceImpl"  interface="com.yyf.dubbo.inf.TestService" version="1.0.0"></dubbo:service>
</beans>

<dubbo:registry address="N/A" /> 不使用註冊中心時 registry address 一定要設置爲N/A

@ImportResource(value = {"classpath:dubbo-provider.xml"})

 

參考地址:

https://blog.csdn.net/u011123972/article/details/89357053

https://blog.csdn.net/qw463800202/article/details/82222771

https://blog.csdn.net/weixin_44946117/article/details/91869171

https://blog.csdn.net/lchpersonal521/article/details/81837583

https://blog.csdn.net/weixin_36898373/article/details/105545066

https://blog.csdn.net/ys3909656/article/details/89674923

https://www.pianshen.com/article/3719367973/

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章