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 2022/10/20 06:28:34 UTC

[GitHub] [dubbo] AlbumenJ opened a new issue, #10765: dubbo.consumer.tag not work on 3.x

AlbumenJ opened a new issue, #10765:
URL: https://github.com/apache/dubbo/issues/10765

   <!-- If you need to report a security issue please visit https://github.com/apache/dubbo/security/policy -->
   
   - [ ] I have searched the [issues](https://github.com/apache/dubbo/issues) of this repository and believe that this is not a duplicate.
   
   ### Environment
   
   * Dubbo version: xxx
   * Operating System version: xxx
   * Java version: xxx
   
   ### Steps to reproduce this issue
   
   1. xxx
   2. xxx
   3. xxx
   
   ```properties
   dubbo.provider.tag=dev
   dubbo.consumer.tag=dev
   ```
   
   Pls. provide [GitHub address] to reproduce this issue.
   
   ### Expected Behavior
   
   <!-- What do you expect from the above steps?-->
   
   ### Actual Behavior
   
   <!-- What actually happens? -->
   
   If there is an exception, please attach the exception trace:
   
   ```
   Just put your stack trace here!
   ```
   


-- 
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] AlbumenJ closed issue #10765: dubbo.consumer.tag not work on 3.x

Posted by GitBox <gi...@apache.org>.
AlbumenJ closed issue #10765: dubbo.consumer.tag not work on 3.x
URL: https://github.com/apache/dubbo/issues/10765


-- 
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] pandaapo commented on issue #10765: dubbo.consumer.tag not work on 3.x

Posted by GitBox <gi...@apache.org>.
pandaapo commented on issue #10765:
URL: https://github.com/apache/dubbo/issues/10765#issuecomment-1286811150

   I used `dubbo-demo-spring-boot` to try to reproduce this bug, but it seems to work well.
   
   I modified the provider `application.yml`:
   ```
   dubbo:
     application:
       name: dubbo-springboot-demo-provider
     protocol:
       name: dubbo
       port: -1
     provider:
       tag: tagA # another instance is configured as tagB
     registry:
       id: zk-registry
       address: zookeeper://127.0.0.1:2181
   #  config-center:
   #    address: zookeeper://127.0.0.1:2181
   #  metadata-report:
   #    address: zookeeper://127.0.0.1:2181
   ```
   I modified the consumer `application.yml`:
   ```
   dubbo:
     application:
       name: dubbo-springboot-demo-consumer
   #  protocol:
   #    name: dubbo
   #    port: -1
     consumer:
       tag: tagB
     registry:
       id: zk-registry
       address: zookeeper://127.0.0.1:2181
   #  config-center:
   #    address: zookeeper://127.0.0.1:2181
   #  metadata-report:
   #    address: zookeeper://127.0.0.1:2181
   ```
   
   This is the result of running consumer:
   ```
   result: I am tag B, Hello world
   result: I am tag B, Hello world
   result: I am tag B, Hello world
   result: I am tag B, Hello world
   result: I am tag B, Hello world
   result: I am tag B, Hello world
   result: I am tag B, Hello world
   result: I am tag B, Hello world
   result: I am tag B, Hello world
   result: I am tag B, Hello world
   ``` 
   
   Does this bug only occur in some specified situation?


-- 
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] pandaapo commented on issue #10765: dubbo.consumer.tag not work on 3.x

Posted by GitBox <gi...@apache.org>.
pandaapo commented on issue #10765:
URL: https://github.com/apache/dubbo/issues/10765#issuecomment-1296829241

   I investigated this bug. Now I want to confirm some questions before I decide what to do next.
   If Spring is configured with `PropertySourcesPlaceholderConfigurer`, the usual way is to write `${key}` to the fields of various forms of Spring beans, so that the key-value configured in the property file can take effect. So `dubbo.consumer.tag` can work when `<dubbo:consumer tag="${key}">` is written in Dubbo configuration file.
   Considering you proposed this issue, I think Dubbo has made some more convenient work against the properties configured by user. The property may be applied even though `<dubbo:consumer tag="${key}">` is not written explicitly.  **Am I right?**
   
   According my guess, I find Dubbo assigns the value from `ModuleEnvironment` to `XxxConfig`.  And `ModuleEnvironment`'s `appConfigMap` is built according to Spring `Environment` when `DubboInfraBeanRegisterPostProcessor#postProcessBeanFactory()` is called. **Am I right?**
   
   ---
   我研究了这个问题,目前有一些不确定的地方想跟您先确认一下。
   如果采用 `PropertySourcesPlaceholderConfigurer`的方式配置Spring,按照通常的使用方式,对于各种形式的Spring bean,只要在需要用到所配属性的字段上写`${key}`,就能注入配置的属性值。所以Dubbo也是一样,如果写了`<dubbo:consumer tag="${key}">`,属性文件中配置的 `dubbo.consumer.tag`就能生效。
   但是鉴于您提了该issue,所以我猜Dubbo也许在此基础之上做了更进一步的工作,即使不用显式地写`<dubbo:consumer tag="${key}">`也能让 `dubbo.consumer.tag`生效。**我的理解对吗?**
   
   按照该思路,我在源码中看到Dubbo在内部用`ModuleEnvironment`给各种`XxxConfig`赋值,而`ModuleEnvironment`是在Spring启动中`DubboInfraBeanRegisterPostProcessor#postProcessBeanFactory()`方法执行的时候构建了`appConfigMap`。**我的理解对吗?**


-- 
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] pandaapo commented on issue #10765: dubbo.consumer.tag not work on 3.x

Posted by GitBox <gi...@apache.org>.
pandaapo commented on issue #10765:
URL: https://github.com/apache/dubbo/issues/10765#issuecomment-1304304788

   用2.7.8的dubbo-demo-annotation和dubbo-demo-xml改了改,分别试了XML配置和Java Config配置的Spring,不论`PropertySourcesPlaceholderConfigurer`、`PropertyPlaceholderConfigurer`,都没生效,是不是在其他版本上?
   [dubbo-demo-annotation.zip](https://github.com/apache/dubbo/files/9942319/dubbo-demo-annotation.zip)
   [dubbo-demo-xml.zip](https://github.com/apache/dubbo/files/9942320/dubbo-demo-xml.zip)
   


-- 
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 commented on issue #10765: dubbo.consumer.tag not work on 3.x

Posted by GitBox <gi...@apache.org>.
AlbumenJ commented on issue #10765:
URL: https://github.com/apache/dubbo/issues/10765#issuecomment-1287690651

   Configured with `PropertySourcesPlaceholderConfigurer`
   
   See `org.apache.dubbo.config.spring.propertyconfigurer.consumer3.PropertySourcesInJavaConfigTest.MyPropertySourcesPlaceholderConfigurer`
   
   Add `dubbo.consumer.tag=dev` into `src/test/java/org/apache/dubbo/config/spring/propertyconfigurer/consumer3/app.properties` and then run `org.apache.dubbo.config.spring.propertyconfigurer.consumer3.PropertySourcesInJavaConfigTest#testCustomPropertySourceBean`. Tag do not apply to service.
   
   
   You can create a test demo with spring and configure with `PropertySourcesPlaceholderConfigurer`.


-- 
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] pandaapo commented on issue #10765: dubbo.consumer.tag not work on 3.x

Posted by GitBox <gi...@apache.org>.
pandaapo commented on issue #10765:
URL: https://github.com/apache/dubbo/issues/10765#issuecomment-1298540034

   感谢指导。和理解的差不多,那我就可以解释大概因为什么导致`dubbo.consumer.tag`不能直接生效了。
   1、对于这些属性,在Dubbo的设计中,最开始存储在`ModuleEnvironment`中,该对象是在`DubboInfraBeanRegisterPostProcessor#postProcessBeanFactory()`执行时构建的,但是在Spring的生命周期中`PropertySourcesPlaceholderConfigurer#postProcessBeanFactory()`执行时机在其之后。
   2、即使调整到`PropertySourcesPlaceholderConfigurer`执行过后,目前`ModuleEnvironment`的构建方式将依旧获取不到配置属性,https://github.com/apache/dubbo/blob/bf991e457f6378364ac6ca36f19edce1891d2804/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/context/DubboInfraBeanRegisterPostProcessor.java#L86-L88 ,因为目前是根据Spring的`ConfigurableEnvironment`来构建,而`PropertySourcesPlaceholderConfigurer`并没有将解析的属性值存储到该对象,而是另外存储在`PropertySources`中。
   
   另外,还有个疑问需要跟您确认。
   如果采用Spring 3.x之后已经过时的`PropertyPlaceholderConfigurer`来配置的话,没有办法像Dubbo现在的设计这样——从Spring某对象中取出解析的属性值应用到`ModuleEnvironment`。因为`PropertyPlaceholderConfigurer`没有对外提供如`PropertySources`之类的属性集合(我从Spring源码没找到,如果有还希望大佬予以指导)。
   所以如果用过时的`PropertyPlaceholderConfigurer`,且没有显式地写`<dubbo:consumer tag="${key}">`导致`dubbo.consumer.tag`不能生效,**这个问题应该不需要解决吧?**


-- 
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 commented on issue #10765: dubbo.consumer.tag not work on 3.x

Posted by GitBox <gi...@apache.org>.
AlbumenJ commented on issue #10765:
URL: https://github.com/apache/dubbo/issues/10765#issuecomment-1299391655

   > 2、即使调整到`PropertySourcesPlaceholderConfigurer`执行过后,目前`ModuleEnvironment`获取属性的方式将依旧拿不到配置属性,
   > 
   > https://github.com/apache/dubbo/blob/bf991e457f6378364ac6ca36f19edce1891d2804/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/context/DubboInfraBeanRegisterPostProcessor.java#L86-L88
   > 
   > ,因为目前是从Spring的`ConfigurableEnvironment`取值,而`PropertySourcesPlaceholderConfigurer`不会将解析的属性值存储到该对象,而是另外存储在`PropertySources`中。
   
   这个有必要的话是可以调整的
   
   > 另外,还有个疑问需要跟您确认。 如果采用Spring 3.x之后已经过时的`PropertyPlaceholderConfigurer`来配置的话,就没办法实现Dubbo让特定格式的配置直接生效的功能。因为`PropertyPlaceholderConfigurer`没有对外提供如`PropertySources`之类的属性集合(我从Spring源码没找到,如果有还希望大佬予以指导)。 所以如果用过时的`PropertyPlaceholderConfigurer`,且没有显式地写`<dubbo:consumer tag="${key}">`导致`dubbo.consumer.tag`不能生效,**这种情况应该不需要解决吧?**
   
   这个方式在 `2.7.8` 版本中是支持的,可以看下之前是怎么实现的,这个理论上来说应该只是一个 bugfix


-- 
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 commented on issue #10765: dubbo.consumer.tag not work on 3.x

Posted by GitBox <gi...@apache.org>.
AlbumenJ commented on issue #10765:
URL: https://github.com/apache/dubbo/issues/10765#issuecomment-1297857126

   > 但是鉴于您提了该issue,所以我猜Dubbo也许在此基础之上做了更进一步的工作,即使不用显式地写<dubbo:consumer tag="${key}">也能让 dubbo.consumer.tag生效。我的理解对吗?
   
   是的
   
   > 按照该思路,我在源码中看到Dubbo在内部用ModuleEnvironment的appConfigMap给各种XxxConfig赋值,这就使得即使不写<dubbo:consumer tag="${key}">也能让dubbo.consumer.tag生效。ModuleEnvironment是在Spring启动中DubboInfraBeanRegisterPostProcessor#postProcessBeanFactory()方法执行的时候构建了appConfigMap。
   
   目前的逻辑只是起到了一个 placeholder 覆盖的作用,但是在 Dubbo 里面可以通过特定格式的配置直接修改(参考 https://dubbo.apache.org/zh/docs3-v2/java-sdk/reference-manual/config/principle/ 以及各个 `XxxConfig` 的 `refresh` 方法)。


-- 
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] pandaapo commented on issue #10765: dubbo.consumer.tag not work on 3.x

Posted by GitBox <gi...@apache.org>.
pandaapo commented on issue #10765:
URL: https://github.com/apache/dubbo/issues/10765#issuecomment-1299408051

   > 这个有必要的话是可以调整的
   
   嗯,`PropertySourcesPlaceholderConfigurer`的,目前有思路解决。
   
   > 这个方式在 `2.7.8` 版本中是支持的,可以看下之前是怎么实现的,这个理论上来说应该只是一个 bugfix
   
   好,`PropertyPlaceholderConfigurer`的,我再看下`2.7.8`版本是怎么实现的。


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