You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@rocketmq.apache.org by GitBox <gi...@apache.org> on 2022/07/06 03:00:59 UTC

[GitHub] [rocketmq] caigy commented on a diff in pull request #4556: Optimized filter example code

caigy commented on code in PR #4556:
URL: https://github.com/apache/rocketmq/pull/4556#discussion_r914371045


##########
example/src/main/java/org/apache/rocketmq/example/filter/SqlFilterConsumer.java:
##########
@@ -17,33 +17,26 @@
 
 package org.apache.rocketmq.example.filter;
 
-import java.util.List;
 import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer;
 import org.apache.rocketmq.client.consumer.MessageSelector;
-import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext;
 import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus;
 import org.apache.rocketmq.client.consumer.listener.MessageListenerConcurrently;
-import org.apache.rocketmq.common.message.MessageExt;
 
 public class SqlFilterConsumer {
+    public static final String CONSUMER_GROUP = "please_rename_unique_group_name";
+    public static final String TOPIC = "SqlFilterTest";
 
     public static void main(String[] args) throws Exception {
 
-        DefaultMQPushConsumer consumer = new DefaultMQPushConsumer("please_rename_unique_group_name");
+        DefaultMQPushConsumer consumer = new DefaultMQPushConsumer(CONSUMER_GROUP);
 
         // Don't forget to set enablePropertyFilter=true in broker
-        consumer.subscribe("SqlFilterTest",
-            MessageSelector.bySql("(TAGS is not null and TAGS in ('TagA', 'TagB'))" +
+        consumer.subscribe(TOPIC, MessageSelector.bySql("(TAGS is not null and TAGS in ('TagA', 'TagB'))" +
                 "and (a is not null and a between 0 and 3)"));
 
-        consumer.registerMessageListener(new MessageListenerConcurrently() {
-
-            @Override
-            public ConsumeConcurrentlyStatus consumeMessage(List<MessageExt> msgs,
-                ConsumeConcurrentlyContext context) {
-                System.out.printf("%s Receive New Messages: %s %n", Thread.currentThread().getName(), msgs);
-                return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
-            }
+        consumer.registerMessageListener((MessageListenerConcurrently) (msgs, context) -> {
+            System.out.printf("%s Receive New Messages: %s %n", Thread.currentThread().getName(), msgs);
+            return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;

Review Comment:
   Clients should still be compatible with JDK6.



-- 
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: dev-unsubscribe@rocketmq.apache.org

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