大战熟女丰满人妻av-荡女精品导航-岛国aaaa级午夜福利片-岛国av动作片在线观看-岛国av无码免费无禁网站-岛国大片激情做爰视频

專注Java教育14年 全國咨詢/投訴熱線:400-8080-105
動力節點LOGO圖
始于2009,口口相傳的Java黃埔軍校
首頁 hot資訊 Dubbo消費者配置的方法

Dubbo消費者配置的方法

更新時間:2022-12-06 10:11:29 來源:動力節點 瀏覽1712次

相信大家對什么是Dubbo已經有所了解,那么,Dubbo消費者配置的方法有哪些?動力節點小編來告訴大家。

消費者配置詳解

Dubbo Consumer的配置有3種方式:XML配置、API調用方式配置、注解方式配置。

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://dubbo.apache.org/schema/dubbo"
    Xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.3.xsd http://dubbo.apache.org/schema /dubbo http://dubbo.apache.org/schema/dubbo/dubbo.xsd">
    <dubbo:application name="hello-world-app" />
    <dubbo:registry address="multicast://224.5.6.7:1234" />
    <dubbo:protocol name="dubbo" port="20880" />
    <dubbo:reference id="demoServiceRemote" interface="com.alibaba.dubbo.demo.DemoService" />
</beans>

注解

參考注解遠程服務

Public class AnnotationConsumeService {
    @com.alibaba.dubbo.config.annotation.Reference
    Public AnnotateService annotateService;
    // ...
}

這種方式的配置和前面xml中的配置是一樣的。

api直接觸發

Import com.alibaba.dubbo.rpc.config.ApplicationConfig;
Import com.alibaba.dubbo.rpc.config.RegistryConfig;
Import com.alibaba.dubbo.rpc.config.ConsumerConfig;
Import com.alibaba.dubbo.rpc.config.ReferenceConfig;
Import com.xxx.XxxService;
// current application configuration
ApplicationConfig application = new ApplicationConfig();
application.setName("yyy");
// Connect to the registry configuration
RegistryConfig registry = new RegistryConfig();
registry.setAddress("10.20.130.230:9090");
registry.setUsername("aaa");
registry.setPassword("bbb");
// Note: ReferenceConfig is a heavy object that internally encapsulates the connection to the registry and the connection to the service provider.
// reference remote service
ReferenceConfig<XxxService> reference = new ReferenceConfig<XxxService>(); // This instance is heavy, encapsulates the connection to the registry and the connection to the provider, please cache it yourself, otherwise it may cause memory and connection leaks.
reference.setApplication(application);
reference.setRegistry(registry); // Multiple registries can use setRegistries()
reference.setInterface(XxxService.class);
reference.setVersion("1.0.0");
// Use xxxService like local beans
XxxService xxxService = reference.get();

方法特殊設置

// Method level configuration
List<MethodConfig> methods = new ArrayList<MethodConfig>();
MethodConfig method = new MethodConfig();
method.setName("createXxx");
method.setTimeout(10000);
method.setRetries(0);
Methods.add(method);
// reference remote service
ReferenceConfig<XxxService> reference = new ReferenceConfig<XxxService>(); // This instance is heavy, encapsulates the connection to the registry and the connection to the provider, please cache it yourself, otherwise it may cause memory and connection leaks.
...
reference.setMethods(methods); // Set method level configuration

消費者調用遠程服務

需要通過 Dubbo 調用遠程服務。具體步驟如下:

1.創建項目 如果已經有項目,可以忽略。創建一個可以在https://start.spring.io/創建的 spring boot 項目。服務的提供者已在提供者部分定義。

2.調用服務

@RestController
Public class UserTestController{
    @Autowired
    Private UserReadService userReadService;
    @RequestMapping("/user/getById")
    Public String getUserById(Long id){
        // just test
        Return userReadService.getUserById(id).toString();
    }
}

3.Dubbo配置

<?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://dubbo.apache.org/schema/dubbo"
    Xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.3.xsd http://dubbo.apache.org/schema /dubbo http://dubbo.apache.org/schema/dubbo/dubbo.xsd">
    <dubbo:application name="hello-world-app" />
    <dubbo:registry address="multicast://224.5.6.7:1234" />
    <dubbo:protocol name="dubbo" port="20880" />
    <dubbo:reference id="userReadService" interface="com.package.UserReadService"check="false" />
</beans>

以上就是關于“Dubbo消費者配置的方法”介紹,大家如果想了解更多可查看Dubbo教程,里面還有更豐富的知識等著大家去學習,希望對大家能夠有所幫助。

提交申請后,顧問老師會電話與您溝通安排學習

免費課程推薦 >>
技術文檔推薦 >>
主站蜘蛛池模板: 又粗又大的机巴好爽视频视频 | 国产综合另类小说色区色噜噜 | 91久久国产精品视频 | 国产在线精品香蕉麻豆 | 久久最近最新中文字幕大全 | 四虎海外在线永久免费看 | 亚洲一区天堂 | 毛片基地免费视频a | 久久这里有精品 | 天天狠狠色综合图片区 | 何以笙箫默在线观看 | 中文字幕在线观看第二页 | 亚洲欧美一区二区三区国产精品 | 九热爱视频精品视频 | 123日本不卡在线观看 | 久久这里只有精品免费播放 | 精品免费久久久久国产一区 | 狠狠色噜噜狠狠狠狠97老肥女 | 一级毛片视屏 | 亚洲精品二三区伊人久久 | 中文字幕曰韩一区二区不卡 | 五月天丁香婷婷综合久久 | 九九精品国产兔费观看久久 | 日本久久久久亚洲中字幕 | 不卡的毛片 | 一及黄色毛片 | 久久99精品久久久久久 | 91啦视频在线观看 | 日日撸夜夜撸网站 | 国产精品成人免费视频99 | 日本aa视频 | 国产成人午夜性视频影院 | 亚洲欧美日韩中文字幕在线一区 | 四虎影视在线麻豆国产 | 狠狠操天天操夜夜操 | 天天上天天干 | 婷婷的五月 | 天天摸天天操天天爽 | 又黄又爽又色的免费毛片 | 亚洲国产99在线精品一区二区 | 亚洲国产精|