LuanLouis commented on a change in pull request #87: [ISSUE #86] add feature: 
consumer listener enabled configuration
URL: https://github.com/apache/rocketmq-spring/pull/87#discussion_r292827951
 
 

 ##########
 File path: 
rocketmq-spring-boot/src/main/java/org/apache/rocketmq/spring/autoconfigure/RocketMQProperties.java
 ##########
 @@ -36,6 +39,16 @@
 
     private Producer producer;
 
+    /**
+     * Configure enable listener or not.
+     * In some particular cases, if you don't want the the listener is enabled 
when container startup,
+     * the configuration pattern is like this :
+     * rocketmq.consumer.listeners.<group-name>.<topic-name>.enabled=<boolean 
value, true or false>
+     * <p>
+     * the listener is enabled by default.
+     */
+    private Consumer consumer = new Consumer();
 
 Review comment:
   This consumer is used in following code to decide whether should be 
registered. the purpose of initialize the consumer by default is keep the 
following logic simple,instead of lot of `if` check logic goes here.
   ```java
   boolean listenerEnabled =
               
(boolean)rocketMQProperties.getConsumer().getListeners().getOrDefault(consumerGroup,
 Collections.EMPTY_MAP)
                   .getOrDefault(topic, true);
   
           if (!listenerEnabled) {
               log.debug(
                   "Consumer Listener (group:{},topic:{}) is not enabled by 
configuration, will ignore initialization.",
                   consumerGroup, topic);
               return;
           }
   ```
   if consumer is not initialized by default,  the code should justified as 
follows, there would be a more complicated `if` check logic:
   ```java
           RocketMQProperties.Consumer consumer = 
rocketMQProperties.getConsumer();
           if (null != consumer) {
               Map<String, Map<String, Boolean>> listeners = 
consumer.getListeners();
               if (null != listeners) {
                   boolean listenerEnabled = 
(Boolean)listeners.getOrDefault(consumerGroup, 
Collections.EMPTY_MAP).getOrDefault(topic, true);
                   if (!listenerEnabled) {
                       log.debug(
                           "Consumer Listener (group:{},topic:{}) is not 
enabled by configuration, will ignore initialization.",
                           consumerGroup, topic);
                       return;
                   }
               }
           }
   ``` 
   **If you perfer the second style, I will modify it.**
   

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to