Closed ld-github closed 4 years ago
官方配置如下:
搜索所有分组
<dubbo:reference interface="com.xxx.MenuService" group="*" merger="true" />
合并指定分组
<dubbo:reference interface="com.xxx.MenuService" group="aaa,bbb" merger="true" />
指定方法合并结果,其它未指定的方法,将只调用一个Group
<dubbo:reference interface="com.xxx.MenuService" group="*">
<dubbo:method name="getMenuItems" merger="true" />
</dubbo:service>
某个方法不合并结果,其它都合并结果
<dubbo:reference interface="com.xxx.MenuService" group="*" merger="true">
<dubbo:method name="getMenuItems" merger="false" />
</dubbo:service>
Hey,
I need help to understand this issue.. could someone write this issue in English? I could be interested in work on this.
@danielamorais org.apache.dubbo.config.annotation.Reference add code
String merger() default "";
use
@Reference(version = "1.0.0", group = "*", merger = "true")
private DemoService demoService;
class org.apache.dubbo.config.ReferenceConfig extends AbstractMethodConfig, it has merger but annotation.Reference not. class org.apache.dubbo.config.spring.util.AnnotationUtils.getAttributes(Annotation annotation, PropertyResolver propertyResolver,boolean ignoreDefaultValue, String... ignoreAttributeNames) will bind annotation value , but add merger() default must is "", beceuse
if (ignoreDefaultValue && nullSafeEquals(attributeValue, getDefaultValue(annotation, attributeName))) {
continue;
}
will ignore ^_^
I think we can close the issue since the attribute of group
of tag
Class: org.apache.dubbo.config.ReferenceConfig.java
// inspect the below method
private void init() {
...
String serviceKey = URL.buildKey(interfaceName, group, version);
}
Dive into the file URL.java, we cannot find any split operation on the attribute group.
public static String buildKey(String path, String group, String version) {
StringBuilder buf = new StringBuilder();
if (group != null && group.length() > 0) {
buf.append(group).append("/"); // Just appends the "group" to the path
}
buf.append(path);
if (version != null && version.length() > 0) {
buf.append(":").append(version);
}
return buf.toString();
}
I think we can close the issue since the attribute of
group
of tag dubbo:reference only supports one name:Class: org.apache.dubbo.config.ReferenceConfig.java
// inspect the below method private void init() { ... String serviceKey = URL.buildKey(interfaceName, group, version); }
Dive into the file URL.java, we cannot find any split operation on the attribute group.
public static String buildKey(String path, String group, String version) { StringBuilder buf = new StringBuilder(); if (group != null && group.length() > 0) { buf.append(group).append("/"); // Just appends the "group" to the path } buf.append(path); if (version != null && version.length() > 0) { buf.append(":").append(version); } return buf.toString(); }
You're right .But we may have a look at this code
public RegistryDirectory(Class<T> serviceType, URL url) {
super(url);
if (serviceType == null)
throw new IllegalArgumentException("service type is null.");
if (url.getServiceKey() == null || url.getServiceKey().length() == 0)
throw new IllegalArgumentException("registry serviceKey is null.");
this.serviceType = serviceType;
this.serviceKey = url.getServiceKey();
this.queryMap = StringUtils.parseQueryString(url.getParameterAndDecoded(Constants.REFER_KEY));
this.overrideDirectoryUrl = this.directoryUrl = url.setPath(url.getServiceInterface()).clearParameters().addParameters(queryMap).removeParameter(Constants.MONITOR_KEY);
String group = directoryUrl.getParameter(Constants.GROUP_KEY, "");
this.multiGroup = group != null && ("*".equals(group) || group.contains(","));
String methods = queryMap.get(Constants.METHODS_KEY);
this.serviceMethods = methods == null ? null : Constants.COMMA_SPLIT_PATTERN.split(methods);
}
首先环境正常,这是我的源码,按照官方文档中的xml初始化的ReferenceBean,但是无法实现分组聚合的效果,设置Group为"*"号,无法找到provider,异常信息Caused by: com.alibaba.dubbo.remoting.RemotingException: com.alibaba.dubbo.remoting.RemotingException: Not found exported service,当我设置Group为注册过的Group时,能正常工作,但是不能设置多个Group,例如:9999,9999a这种格式,它会去找9999,9999a的gourp,而没有根据","做split分别去找9999和9999a两个分组,求助,谢谢!