我在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
对于相同的consumerGroup,所有consumer实例的标记设置都应该相同。阅读此了解更多信息https://help.aliyun.com/document_detail/43523.html
原回答者GitHub用户Zanglei06
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。
阿里云拥有国内全面的云原生产品技术以及大规模的云原生应用实践,通过全面容器化、核心技术互联网化、应用 Serverless 化三大范式,助力制造业企业高效上云,实现系统稳定、应用敏捷智能。拥抱云原生,让创新无处不在。