You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@dubbo.apache.org by GitBox <gi...@apache.org> on 2018/04/18 02:05:37 UTC

[GitHub] gougouzcm opened a new issue #1622: Can the dubbo router be more customized

gougouzcm opened a new issue #1622: Can the dubbo router be more customized  
URL: https://github.com/apache/incubator-dubbo/issues/1622
 
 
   I want to use the feature  [1438](https://github.com/apache/incubator-dubbo/pull/1438),
   But the code seem has not been merge to master.
   By the way ,I think the lable  `<dubbo:provider unit="anything"/>`  may not be that useful for ABtest.
   The lable must write in xml and can not change dynamic.
   
   The most common situation is ConsumerA --->  ProviderA ,then ProviderA  get a error .
   Now I fix the bug and want to verify it ,So I startup a addition ProviderA (I call it providerAPlus).
   The normal requests ( I mean the not verify request for this fix ) should not access to ProviderAPlus, 
   But when I want the request ( from developers )access ProviderAPlus ,I don't want to restart the ConsumerA and add   `<dubbo:provider unit="test"/>`  in the xml or startup a consumerAPlus,
   Then the nginx help me to send the request from app/html to ConsumerAPlus( via cookie  or header).
   
   The perfect solution is I startup the ProviderAPlus ( which xml contails `<dubbo:provider unit="test"/> )
   Then request from APP/html first come into a httpFilter( I call it ABtestFilter), In the filter I judge  if the current request is a testRequest via cooike/header。 The I set something in ThreadLocal . 
   The the dubbo give me a way like  `<dubbo:provider groupRouter="test"/>` as a SPI .
   see  [AbstractDirectory.java](https://github.com/apache/incubator-dubbo/blob/master/dubbo-cluster/src/main/java/com/alibaba/dubbo/rpc/cluster/directory/AbstractDirectory.java)
   In the method 
   ```
   1. protected void setRouters(List<Router> routers) {
   2.         // copy list
   3.         routers = routers == null ? new ArrayList<Router>() : new ArrayList<Router>(routers);
   4.         // append url router
   5.         String routerkey = url.getParameter(Constants.ROUTER_KEY);
   6.         if (routerkey != null && routerkey.length() > 0) {
   7.             RouterFactory routerFactory = ExtensionLoader.getExtensionLoader(RouterFactory.class).getExtension(routerkey);
   8.             routers.add(routerFactory.getRouter(url));
   9.         }
   10.         // append mock invoker selector
   11.         routers.add(new MockInvokersSelector());
   12.         Collections.sort(routers);
   13.         this.routers = routers;
   14.     }
   
   ```
   In my custom spi router , I can read the variable in ThreadLocal I put when the request come into httpFilter .  So I know it is a test request from developers ,I will route it to providerAPlus.
   
   The advantage :
      I don't need to startup a ConsumerAPlus  or  change the xml in ConsumerA the restart ConsumerA  
   
   The advice I said may too customized  But In the actual production environment , It really a common question 
   
   By the way ,I want to know when the next version can be publisher ,I want to use the feature  [1438](https://github.com/apache/incubator-dubbo/pull/1438)
   
   can any one help me . thk.
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services