转!rocketMq监听多个topic
实现 RocketMQPushConsumerLifecycleListener,手动增加监听的topic
方式1:
https://blog.csdn.net/weixin_38456989/article/details/127943679
@Component @RocketMQMessageListener(topic = "",consumerGroup="group1") public class MessageListener1 implements RocketMQListener<String>, RocketMQPushConsumerLifecycleListener { @Override public void onMessage(String str) { } @Override public void prepareStart(DefaultMQPushConsumer consumer) { try{ consumer.subscribe("topic-a","*"); consumer.subscribe("topic-b","*"); consumer.registerMessageListener((List<MessageExt> messages, ConsumeConcurrentlyContext context) -> { if (CollectionUtils.isNotEmpty(messages)) { for (MessageExt message : messages) { System.out.println(Thread.currentThread().getName()+"消费完成:"+message.getTopic()+ new String(message.getBody())); } } return ConsumeConcurrentlyStatus.CONSUME_SUCCESS; }); }catch (MQClientException e){ e.printStackTrace(); } } }
方式2:
https://www.cnblogs.com/qqyb/p/16708116.html
RocketMQPushConsumerLifecycleListener