做如下更改就可以支持
`@Override
public <T> List<Invoker<T>> route(List<Invoker<T>> invokers, URL url,
Invocation invocation) throws RpcException {
if (CollectionUtils.isEmpty(invokers)) {
return invokers;
}
String tag = StringUtils.isEmpty(invocation.getAttachment(TAG_KEY)) ?
url.getParameter(TAG_KEY) :
invocation.getAttachment(TAG_KEY);
List<Invoker<T>> result = invokers;
// if we are requesting for a Provider with a specific tag
if (StringUtils.isNotEmpty(tag)) {
if(tagRouterRule == null || !tagRouterRule.isValid() ||
!tagRouterRule.isEnabled()){
result = filterInvoker(invokers, invoker ->
tag.equals(invoker.getUrl().getParameter(TAG_KEY)));
if (CollectionUtils.isEmpty(result)){
result = filterInvoker(result, invoker -> {
String localTag =
invoker.getUrl().getParameter(TAG_KEY);
return StringUtils.isEmpty(localTag);
});
}
return result;
}
List<String> addresses =
tagRouterRule.getTagnameToAddresses().get(tag);
// filter by dynamic tag group first
if (CollectionUtils.isNotEmpty(addresses)) {
result = filterInvoker(invokers, invoker ->
addressMatches(invoker.getUrl(), addresses));
// if result is not null OR it's null but force=true, return
result directly
if (CollectionUtils.isNotEmpty(result) ||
tagRouterRule.isForce()) {
return result;
}
} else {
// dynamic tag group doesn't have any item about the requested
app OR it's null after filtered by
// dynamic tag group but force=false. check static tag
result = filterInvoker(invokers, invoker ->
tag.equals(invoker.getUrl().getParameter(TAG_KEY)));
}
// If there's no tagged providers that can match the current tagged
request. force.tag is set by default
// to false, which means it will invoke any providers without a tag
unless it's explicitly disallowed.
if (CollectionUtils.isNotEmpty(result) || isForceUse(invocation)) {
return result;
}
// FAILOVER: return all Providers without any tags.
else {
List<Invoker<T>> tmp = filterInvoker(invokers, invoker ->
addressNotMatches(invoker.getUrl(),
tagRouterRule.getAddresses()));
return filterInvoker(tmp, invoker ->
StringUtils.isEmpty(invoker.getUrl().getParameter(TAG_KEY)));
}
} else {
// List<String> addresses = tagRouterRule.filter(providerApp);
// return all addresses in dynamic tag group.
if(tagRouterRule != null && tagRouterRule.isValid() &&
tagRouterRule.isEnabled()){
List<String> addresses = tagRouterRule.getAddresses();
if (CollectionUtils.isNotEmpty(addresses)) {
result = filterInvoker(invokers, invoker ->
addressNotMatches(invoker.getUrl(), addresses));
// 1. all addresses are in dynamic tag group, return empty
list.
if (CollectionUtils.isEmpty(result)) {
return result;
}
// 2. if there are some addresses that are not in any
dynamic tag group, continue to filter using the
// static tag group.
}
}
return filterInvoker(result, invoker -> {
String localTag = invoker.getUrl().getParameter(TAG_KEY);
return StringUtils.isEmpty(localTag) || (tagRouterRule != null
&& !tagRouterRule.getTagNames().contains(localTag));
});
}
}`
[ Full content available at:
https://github.com/apache/incubator-dubbo/issues/3319 ]
This message was relayed via gitbox.apache.org for
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]