开发者社区 > 云原生 > 正文

无法对同一消费者组的PushConsumers使用筛选器

我在RocketMQ中玩消息过滤器,发现当消费者在同一消费者组中时,基于标记和基于SQL的过滤器不起作用。以下是RocketMQ环境:

我多次运行ProducerApp,消息中包含“tag1”或“tag2”。但在这两个消费者应用程序上都没有收到消息。

Version 4.8.0, single instance

1、broker.conf

brokerClusterName = DefaultCluster brokerName = broker-a brokerId = 0 deleteWhen = 04 fileReservedTime = 48 brokerRole = ASYNC_MASTER flushDiskType = ASYNC_FLUSH enablePropertyFilter=true

2、Consumer1 App

public class ConsumerApp { public static void main(String[] args) throws Exception { DefaultMQPushConsumer consumer = new DefaultMQPushConsumer("consumerGroup1"); consumer.setNamesrvAddr("127.0.0.1:9876"); consumer.subscribe("testtopic", "tag1"); consumer.registerMessageListener(new MessageListenerConcurrently() { @Override public ConsumeConcurrentlyStatus consumeMessage(List msgs, ConsumeConcurrentlyContext context) { System.out.printf("consumer %s, group %s Receive New Messages: %s %n", "consumer1", "consumerGroup1", msgs); return ConsumeConcurrentlyStatus.CONSUME_SUCCESS; } }); consumer.start(); } }

3、Consumer2 App

public class ConsumerApp2 { public static void main(String[] args) throws Exception { DefaultMQPushConsumer consumer = new DefaultMQPushConsumer("consumerGroup1"); consumer.setNamesrvAddr("127.0.0.1:9876"); consumer.subscribe("testtopic", "tag2"); consumer.registerMessageListener(new MessageListenerConcurrently() { @Override public ConsumeConcurrentlyStatus consumeMessage(List msgs, ConsumeConcurrentlyContext context) { System.out.printf("consumer %s, group %s Receive New Messages: %s %n", "consumer2", "consumerGroup1", msgs); return ConsumeConcurrentlyStatus.CONSUME_SUCCESS; } }); consumer.start(); } }

4、Producer App

public class ProducerApp { public static void main(String[] args) throws Exception { DefaultMQProducer producer = new DefaultMQProducer("ProducerGroup"); producer.setNamesrvAddr("127.0.0.1:9876"); producer.start(); Message msg = new Message("testtopic", "tag1", "helloworld".getBytes(RemotingHelper.DEFAULT_CHARSET)); producer.send(msg); producer.shutdown(); } }

原提问者GitHub用户jinrongluo

展开
收起
芬奇福贵 2023-05-26 10:58:44 101 0
1 条回答
写回答
取消 提交回答
  • 对于相同的consumerGroup,所有consumer实例的标记设置都应该相同。阅读此了解更多信息https://help.aliyun.com/document_detail/43523.html

    原回答者GitHub用户Zanglei06

    2023-05-26 17:21:32
    赞同 展开评论 打赏

阿里云拥有国内全面的云原生产品技术以及大规模的云原生应用实践,通过全面容器化、核心技术互联网化、应用 Serverless 化三大范式,助力制造业企业高效上云,实现系统稳定、应用敏捷智能。拥抱云原生,让创新无处不在。

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载