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

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

Dubbo消費(fèi)者配置的方法

更新時間:2022-12-06 10:11:29 來源:動力節(jié)點(diǎn) 瀏覽1993次

相信大家對什么是Dubbo已經(jīng)有所了解,那么,Dubbo消費(fèi)者配置的方法有哪些?動力節(jié)點(diǎn)小編來告訴大家。

消費(fèi)者配置詳解

Dubbo Consumer的配置有3種方式:XML配置、API調(diào)用方式配置、注解方式配置。

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>

注解

參考注解遠(yuǎn)程服務(wù)

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

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

api直接觸發(fā)

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();

方法特殊設(shè)置

// 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

消費(fèi)者調(diào)用遠(yuǎn)程服務(wù)

需要通過 Dubbo 調(diào)用遠(yuǎn)程服務(wù)。具體步驟如下:

1.創(chuàng)建項(xiàng)目 如果已經(jīng)有項(xiàng)目,可以忽略。創(chuàng)建一個可以在https://start.spring.io/創(chuàng)建的 spring boot 項(xiàng)目。服務(wù)的提供者已在提供者部分定義。

2.調(diào)用服務(wù)

@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>

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

提交申請后,顧問老師會電話與您溝通安排學(xué)習(xí)

免費(fèi)課程推薦 >>
技術(shù)文檔推薦 >>
主站蜘蛛池模板: 国四虎影永久 | 天天射天天操天天色 | www.伊人网| 欧美日韩国产亚洲一区二区三区 | 成人精品一区二区不卡视频 | 国产精品久久久久影院色 | 亚洲七七久久精品中文国产 | 亚洲成aⅴ人片在线观 | 国产精品视频一区二区三区 | 国产一区二区免费福利片 | 97免费视频观看 | 免费一看一级毛片全播放 | 91嫩草国产线免费观看 | 亚洲欧美精品中字久久99 | 亚洲一区二区日韩欧美gif | 久久99久久99精品免观看不卡 | 亚洲精品久久麻豆蜜桃 | 国内免费一区二区三区视频 | 五月色婷婷六月噜噜 | 欧美日韩中文字幕在线手机版本 | 成人高清视频在线观看大全 | 一区二区三区不卡免费视频97 | 欧美亚洲综合一区 | 日本一区二区三区中文字幕 | 综合欧美日韩一区二区三区 | 奇米影视第七色 | 欧美整片在线 | 日本 欧美 国产 | 香蕉亚洲欧洲在线一区 | 国产精品高清视亚洲一区二区 | 亚洲精品乱码久久久久久蜜桃 | 日本视频不卡 | 中文字幕日韩高清 | 91久久国产精品视频 | 久久国产偷 | 久久精品国产主播一区二区 | 色偷偷成人网免费视频男人的天堂 | 久草新在线观看 | 99爱网站| 免费看一毛一级毛片视频 | 亚洲国产欧美另类 |