欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

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

服務(wù)分組

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

實現(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)一個可用組的實現(xiàn))

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

分組聚合

按組合并返回結(jié)果,比如菜單服務(wù),接口一樣,但有多種實現(xiàn),用group區(qū)分,現(xiàn)在消費方需從每種group中調(diào)用一次返回結(jié)果,合并結(jié)果返回,這樣就可以實現(xiàn)聚合菜單項。(從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)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論