最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

基于dubbo分組group的一些總結(jié)

 更新時間:2023年03月21日 16:35:21   作者:普通網(wǎng)友  
這篇文章主要介紹了關(guān)于dubbo分組group的一些總結(jié),具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教

服務(wù)分組

1.當(dāng)一個接口有多種實(shí)現(xiàn)時,可用使用group分組。

實(shí)現(xiàn)代碼如下:

package com.xxx.service;

public interface MyDubboGroupService {

	public String print();
	
}


package com.xxx.service.impl;

import com.xxx.service.MyDubboGroupService;

public class FeebackService implements MyDubboGroupService {

	@Override
	public String print() {
		// TODO Auto-generated method stub
		return "feedback";
	}

}


package com.xxx.service.impl;

import com.xxx.service.MyDubboGroupService;

public class CmsService implements MyDubboGroupService {

	@Override
	public String print() {
		// TODO Auto-generated method stub
		return "cms";
	}

}

applicationContext.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">

	<!-- 配置Bean -->
	<bean id="feebackService" class="com.xxx.service.impl.FeebackService" />
	<bean id="cmsService" class="com.xxx.service.impl.CmsService" />
	
	<!-- 引入配置文件 -->
	<import resource="classpath:dubbo.xml" />
	
</beans>

dubbo.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">

?? ?<!-- 指定服務(wù)名字 -->
?? ?<dubbo:application name="dubboGroup" />

?? ?<!-- 聲明服務(wù)注冊中心 -->
?? ?<dubbo:registry protocol="zookeeper" address="127.0.0.1:2181" />

?? ?<!-- 暴露你的服務(wù)地址 -->
?? ?<dubbo:service interface="com.xxx.service.MyDubboGroupService" group="feedback" />
?? ?<dubbo:service interface="com.xxx.service.MyDubboGroupService" group="cms" />

</beans>

調(diào)用端dubbo.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">

?? ?<!-- 指定web服務(wù)名字 -->
?? ?<dubbo:application name="dubboGroup" />
?? ?
?? ?<!-- 聲明服務(wù)注冊中心 -->
?? ?<dubbo:registry protocol="zookeeper" address="127.0.0.1:2181" />

?? ?<!-- 暴露你的服務(wù)地址 -->
?? ?<dubbo:reference id="feebackService" interface="com.xxx.service.MyDubboGroupService" group="feedback" />
?? ?<dubbo:reference id="cmsService" interface="com.xxx.service.MyDubboGroupService" group="cms" />
?? ?<!-- 任意組 -->
?? ?<dubbo:reference id="autoService" interface="com.xxx.service.MyDubboGroupService" group="*" />
?? ?
</beans>

調(diào)用代碼如下:

package com.xxx.application;

import java.io.IOException;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.xxx.service.MyDubboGroupService;

public class DubboApplication {
?? ?
?? ?public static void main(String[] args) throws IOException {
?? ??? ?ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
?? ??? ?// 訪問feedback接口
?? ??? ?MyDubboGroupService feebackService = (MyDubboGroupService) ctx.getBean("feebackService");
?? ??? ?System.out.println(feebackService.print());
?? ??? ?// 訪問member接口
?? ??? ?MyDubboGroupService cmsService = (MyDubboGroupService) ctx.getBean("cmsService");
?? ??? ?System.out.println(cmsService.print());
?? ??? ?// 訪問隨機(jī)接口
?? ??? ?MyDubboGroupService autoService = (MyDubboGroupService) ctx.getBean("autoService");
?? ??? ?System.out.println(autoService.print());
?? ?}
?? ?
}

2.上面調(diào)用端dubbo.xml 配置出現(xiàn)的任意組:(2.2.0以上版本支持,總是只調(diào)一個可用組的實(shí)現(xiàn))

<dubbo:reference id="autoService" interface="com.xxx.service.MyDubboGroupService" group="*" />

分組聚合

按組合并返回結(jié)果,比如菜單服務(wù),接口一樣,但有多種實(shí)現(xiàn),用group區(qū)分,現(xiàn)在消費(fèi)方需從每種group中調(diào)用一次返回結(jié)果,合并結(jié)果返回,這樣就可以實(shí)現(xiàn)聚合菜單項(xiàng)。(從2.1.0版本開始支持)

配置如:(搜索所有分組)

<dubbo:reference interface="com.xxx.MenuService" group="*" merger="true" />

或:(合并指定分組)

<dubbo:reference interface="com.xxx.MenuService" group="aaa,bbb" merger="true" />

或:(指定方法合并結(jié)果,其他未指定的方法,將只調(diào)用一個Group)

<dubbo:reference interface="com.xxx.MenuService" group="*">
    <dubbo:method name="getMenuItems" merger="true"/>
</dubbo:reference>

或:(某個方法不合并結(jié)果,其他都合并結(jié)果)

<dubbo:reference interface="com.xxx.MenuService" group="*" merger="true">
    <dubbo:method name="getMenuItems" merger="false"/>
</dubbo:reference>

或:(指定合并策略,缺省根據(jù)返回值類型自動匹配,如果同一類型有兩個合并器時,需指定合并器的名稱)

<dubbo:reference interface="com.xxx.MenuService" group="*">
    <dubbo:method name="getMenuItems" merger="mymerge"/>
</dubbo:reference>

或:(指定合并方法,將調(diào)用返回結(jié)果的指定方法進(jìn)行合并,合并方法的參數(shù)類型必須是返回結(jié)果類型本身)

<dubbo:reference interface="com.xxx.MenuService" group="*">
    <dubbo:method name="getMenuItems" merger=".addAll"/>
</dubbo:reference>

總結(jié)

以上為個人經(jīng)驗(yàn),希望能給大家一個參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • Maven搭建springboot項(xiàng)目的方法步驟

    Maven搭建springboot項(xiàng)目的方法步驟

    這篇文章主要介紹了Maven搭建springboot項(xiàng)目的方法步驟,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-04-04
  • java的內(nèi)部類和外部類用法講解

    java的內(nèi)部類和外部類用法講解

    本文詳細(xì)講解了java的內(nèi)部類和外部類用法,文中通過示例代碼介紹的非常詳細(xì)。對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2021-12-12
  • Java實(shí)現(xiàn)MD5消息摘要算法

    Java實(shí)現(xiàn)MD5消息摘要算法

    本篇文章主要介紹了Java實(shí)現(xiàn)MD5消息摘要算法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-04-04
  • springboot配置文件中使用${}注入值的兩種方式小結(jié)

    springboot配置文件中使用${}注入值的兩種方式小結(jié)

    這篇文章主要介紹了springboot配置文件中使用${}注入值的兩種方式小結(jié),具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-03-03
  • Java中的WeakHashMap詳解

    Java中的WeakHashMap詳解

    這篇文章主要介紹了Java中的WeakHashMap詳解,WeakHashMap可能平時使用的頻率并不高,但是你可能聽過WeakHashMap會進(jìn)行自動回收吧,下面就對其原理進(jìn)行分析,需要的朋友可以參考下
    2023-09-09
  • 如何使用IDEA2022.1?創(chuàng)建Spring?Boot項(xiàng)目

    如何使用IDEA2022.1?創(chuàng)建Spring?Boot項(xiàng)目

    這篇文章主要介紹了如何使用IDEA2022.1?創(chuàng)建Spring?Boot項(xiàng)目,大家在使用idea開發(fā)工具時發(fā)現(xiàn)給以往的版本略微的不同,細(xì)心的小編在此記錄下,需要的朋友可以參考下
    2022-08-08
  • 多線程_解決Runnable接口無start()方法的情況

    多線程_解決Runnable接口無start()方法的情況

    這篇文章主要介紹了多線程_解決Runnable接口無start()方法的情況,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2021-03-03
  • java的jps命令使用詳解

    java的jps命令使用詳解

    這篇文章介紹了java的jps命令使用詳解,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2021-12-12
  • Java Scanner類用法及nextLine()產(chǎn)生的換行符問題實(shí)例分析

    Java Scanner類用法及nextLine()產(chǎn)生的換行符問題實(shí)例分析

    這篇文章主要介紹了Java Scanner類用法及nextLine()產(chǎn)生的換行符問題,結(jié)合實(shí)例形式分析了Scanner類功能、hasNextInt()和nextInt()方法使用及nextLine()產(chǎn)生的換行符問題解決方法,需要的朋友可以參考下
    2019-03-03
  • Java OpenCV利用KNN算法實(shí)現(xiàn)圖像背景移除

    Java OpenCV利用KNN算法實(shí)現(xiàn)圖像背景移除

    這篇文章主要為大家介紹了Java OpenCV利用K最鄰近(KNN,K-NearestNeighbor)分類算法實(shí)現(xiàn)圖像背景移除的示例代碼,需要的可以參考一下
    2022-01-01

最新評論

五大连池市| 固原市| 巴里| 刚察县| 和田县| 汝州市| 二手房| 张家界市| 化德县| 惠来县| 汽车| 双桥区| 中超| 鸡西市| 开平市| 深水埗区| 广水市| 延长县| 图们市| 麻栗坡县| 高平市| 沛县| 安陆市| 定安县| 汉中市| 乌苏市| 澳门| 西乌珠穆沁旗| 诸城市| 临清市| 山东省| 汝南县| 商河县| 含山县| 新巴尔虎右旗| 舞钢市| 开化县| 乡宁县| 泾源县| 梅州市| 新沂市|