rocketmq-spring
rocketmq-spring copied to clipboard
can subscribe more than one topics in one consumer ?
for now , one consumer can sub one topic by @RocketMQMessageListener
@Service
@RocketMQMessageListener(topic = "${demo.rocketmq.topic}", consumerGroup = "string_consumer", selectorExpression = "${demo.rocketmq.tag}", tlsEnable = "${demo.rocketmq.tlsEnable}")
public class StringConsumer implements RocketMQListener<String> {
@Override
public void onMessage(String message) {
System.out.printf("------- StringConsumer received: %s \n", message);
}
}
i tried two consumer class sub one topic, only one topic works and found why :

hope to support more than one topic for consumers
the same question
可以声明两个rocketmqlistener,指定不同的consumer group跟topic
一个消费者是可以同时订阅多个topic 的。详情查看官方文档,订阅关系:https://rocketmq.apache.org/zh/docs/4.x/bestPractice/07subscribe#13-%E8%AE%A2%E9%98%85%E5%A4%9A%E4%B8%AAtopic%E4%B8%94%E8%AE%A2%E9%98%85%E5%A4%9A%E4%B8%AAtag
代码示例如下: