guipengfei opened a new issue, #11913:
URL: https://github.com/apache/dubbo/issues/11913
环境:dubbo 3.0.8 + nacos 2.1.0
需求概述:自定义路由,根据前端传的参数,动态选择符合条件的provider
consumer端配置:
dubbo.application.version=comsumer-1.0.0
provider老版本配置:
dubbo.application.version=provider-1.0.0
provider新版本配置:
dubbo.application.version=provider-2.0.0
provider端新老版本同时提供服务,根据前端的version参数,动态调用对应的provider
以下为自定义路由的伪代码:
```
@Activate(group = CommonConstants.CONSUMER)
public class MyRouterFactory extends CacheableRouterFactory {
@Override
protected Router createRouter(URL url) {
return new MyRouter();
}
}
public class MyRouter extends AbstractRouter {
public MyRouter() {
setPriority(100);
}
@Override
public <T> RouterResult<Invoker<T>> route(List<Invoker<T>> invokers, URL
url, Invocation invocation, boolean needToPrintMessage) throws RpcException {
// 前端动态传递的版本号
String version =
RpcContext.getServiceContext().getAttachment("version");
if (StrUtil.isNotEmpty(version)) {
// 符合条件的invokers
List<Invoker<T>> targetInvokers = new ArrayList<>();
for(Invoker<T> invoker: invokers) {
//
**问题:这里取到的版本号,始终是consumer端的comsumer-1.0.0,而不是期望的provider-1.0.0/provider-2.0.0**
String currentVersion =
invoker.getUrl().getParameter("application.version");
// TODO 根据provider的版本号判断是否符合
// ...
}
return new RouterResult<>(targetInvokers);
}
return new RouterResult<>(invokers);
}
}
```
按理List<Invoker<T>>
invokers是所有可调用的provider集合,但为何里面的参数信息,不是对应的provider端的,该如何才能取到呢?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]