You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by GitBox <gi...@apache.org> on 2018/08/19 06:33:58 UTC

[GitHub] fingthinking opened a new issue #2321: Does provider "async = true" need to be remove from url when register to registry?

fingthinking opened a new issue #2321: Does provider "async = true" need to be remove from url when register to registry?
URL: https://github.com/apache/incubator-dubbo/issues/2321
 
 
   - [ ] I have searched the [issues](https://github.com/apache/incubator-dubbo/issues) of this repository and believe that this is not a duplicate.
   - [ ] I have checked the [FAQ](https://github.com/apache/incubator-dubbo/blob/master/FAQ.md) of this repository and believe that this is not a duplicate.
   
   ### Environment
   
   * Dubbo version:  2.7.0-SNAPSHOT
   
   ### Step to reproduce this issue
   
   1. https://github.com/apache/incubator-dubbo/blob/master/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryProtocol.java
   ```java
    private URL getRegisteredProviderUrl(final Invoker<?> originInvoker) {
           URL providerUrl = getProviderUrl(originInvoker);
           //The address you see at the registry
           return providerUrl.removeParameters(getFilteredKeys(providerUrl))
                   .removeParameter(Constants.MONITOR_KEY)
                   .removeParameter(Constants.BIND_IP_KEY)
                   .removeParameter(Constants.BIND_PORT_KEY)
                   .removeParameter(QOS_ENABLE)
                   .removeParameter(QOS_PORT)
                   .removeParameter(ACCEPT_FOREIGN_IP)
                   .removeParameter(VALIDATION_KEY)
                   .removeParameter(INTERFACES);
       }
   TO
    private URL getRegisteredProviderUrl(final Invoker<?> originInvoker) {
           URL providerUrl = getProviderUrl(originInvoker);
           Set<String> keySet = providerUrl.getParameters().keySet();
           List<String> asyncKey = new ArrayList<>();
           for(String key : keySet) {
               if(key.endsWith(Constants.ASYNC_KEY)) {
                   asyncKey.add(key);
               }
           }
           //The address you see at the registry
           return providerUrl.removeParameters(getFilteredKeys(providerUrl))
                   .removeParameter(Constants.MONITOR_KEY)
                   .removeParameter(Constants.BIND_IP_KEY)
                   .removeParameter(Constants.BIND_PORT_KEY)
                   .removeParameter(QOS_ENABLE)
                   .removeParameter(QOS_PORT)
                   .removeParameter(ACCEPT_FOREIGN_IP)
                   .removeParameter(VALIDATION_KEY)
                   .removeParameter(INTERFACES)
                   .removeParameters(asyncKey);
       }
   ```
   
   that if Provider use "provider async" like this:
   ```Java
    public String sayHello(String name) {
           System.out.println("Main sayHello() method start.");
           final AsyncContext asyncContext = RpcContext.startAsync();
           new Thread(() -> {
               asyncContext.signalContextSwitch();
               System.out.println("Attachment from consumer: " + RpcContext.getContext().getAttachment("consumer-key1"));
               System.out.println("    -- Async start.");
               try {
                   Thread.sleep(500);
               } catch (InterruptedException e) {
                   e.printStackTrace();
               }
               asyncContext.write("Hello " + name + ", response from provider.");
               System.out.println("    -- Async end.");
           }).start();
           System.out.println("Main sayHello() method end.");
           return "hello, " + name;
       }
    <dubbo:method name="sayHello" async="true"/>
   ```
   and consumer user dubbo version low than 2.7.0-SNAPSHOT, 
   "async = true" will know from provider registed url, that need consumer use old async to invoke this method. But it is not what we expected, we think async should only be set by consumer itself.
   英文不太好,中文版:
   1. Provider版本使用 2.7.0-SNAPSHOT版本,然后发布接口使用了"provider async"的方式(见上面第二段代码),则需要在发布的时候添加` <dubbo:method name="sayHello" async="true"/>`则会将 async=true 的标记注册到注册中心,这时候就会将标记透传到 Consumer 端,导致服务调用变成异步的,而出现返回值为 null 的情况。
   2. 根据我个人的理解,async 标记应该仅由 provider 或 consumer 自己指定,而不应该透传到对方感知。
   

----------------------------------------------------------------
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

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