You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by "guipengfei (via GitHub)" <gi...@apache.org> on 2023/03/24 07:59:33 UTC

[GitHub] [dubbo] guipengfei opened a new issue, #11913: 消费者端invoker.getUrl().getParameter("application.version")无法获取到待调用的provider里的应用版本号

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: notifications-unsubscribe@dubbo.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo] eye-gu commented on issue #11913: 消费者端invoker.getUrl().getParameter("application.version")无法获取到待调用的provider里的应用版本号

Posted by "eye-gu (via GitHub)" <gi...@apache.org>.
eye-gu commented on issue #11913:
URL: https://github.com/apache/dubbo/issues/11913#issuecomment-1482550740

   也可以试一下 dubbo.provider.parameters


-- 
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: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo] liufeiyu1002 commented on issue #11913: 消费者端invoker.getUrl().getParameter("application.version")无法获取到待调用的provider里的应用版本号

Posted by "liufeiyu1002 (via GitHub)" <gi...@apache.org>.
liufeiyu1002 commented on issue #11913:
URL: https://github.com/apache/dubbo/issues/11913#issuecomment-1482527845

   因为默认消费端优先。 你可以自己扩展一个 `ProviderFirstParams` 的实现,可以参考 `DefaultProviderFirstParams` 这个,将你要的字段设置为服务端优先就可以获取到了


-- 
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: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo] guipengfei commented on issue #11913: 消费者端invoker.getUrl().getParameter("application.version")无法获取到待调用的provider里的应用版本号

Posted by "guipengfei (via GitHub)" <gi...@apache.org>.
guipengfei commented on issue #11913:
URL: https://github.com/apache/dubbo/issues/11913#issuecomment-1484392539

   > 也可以试一下 dubbo.provider.parameters
     确实dubbo.provider.parameters参数更合适,但dubbo 3.0.8版本配置此参数启动会报错,
   https://github.com/apache/dubbo/issues/10304
   
     且还是会优先取到消费者端的,扩展ProviderFirstParams后已解决


-- 
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: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo] AlbumenJ closed issue #11913: 消费者端invoker.getUrl().getParameter("application.version")无法获取到待调用的provider里的应用版本号

Posted by "AlbumenJ (via GitHub)" <gi...@apache.org>.
AlbumenJ closed issue #11913: 消费者端invoker.getUrl().getParameter("application.version")无法获取到待调用的provider里的应用版本号
URL: https://github.com/apache/dubbo/issues/11913


-- 
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: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org