apache / rocketmq-spring

Apache RocketMQ Spring Integration
https://rocketmq.apache.org/
Apache License 2.0
2.09k stars 894 forks source link

一个应用只允许一个gid,但是有好几个消费类(不同业务不同的topic),导致订阅关系不一致 #653

Closed hachikozjq closed 3 months ago

hachikozjq commented 3 months ago

如题,有没有好的解决方案? @RocketMQMessageListener( topic = "topic1", consumerGroup = "spring-application-name", messageModel = MessageModel.CLUSTERING ) public class A{ }

@RocketMQMessageListener( topic = "topic2", consumerGroup = "spring-application-name", messageModel = MessageModel.CLUSTERING ) public class B{ }

难道要用一个类去监听所有的topic,然后再通过topic判断分别再去调用其他的类?

drpmma commented 3 months ago

最简单的解决方案,不要让gid和应用绑定,gid本身就是一个消费组集群的概念,和应用不应该绑定。

The simplest solution is not to bind the gid with the application, as the gid itself represents the concept of a consumer group cluster and should not be tied to the application.

drpmma commented 3 months ago

在rocketmq中,可以通过consumer多次调用subscribe,使得一个consumer能够同时订阅多个topic;阅读了一下rocketmq-spring的代码,org.apache.rocketmq.spring.support.DefaultRocketMQListenerContainer,看起来是不支持这种做法的。

In RocketMQ, a consumer can subscribe to multiple topics by calling the subscribe method multiple times, allowing a single consumer to simultaneously subscribe to multiple topics. After reviewing the code of rocketmq-spring, specifically org.apache.rocketmq.spring.support.DefaultRocketMQListenerContainer, it appears that this approach is not supported.

hachikozjq commented 3 months ago

在rocketmq中,可以通过consumer多次调用subscribe,使得一个consumer能够同时订阅多个topic;阅读了一下rocketmq-spring的代码,org.apache.rocketmq.spring.support.DefaultRocketMQListenerContainer,看起来是不支持这种做法的。

In RocketMQ, a consumer can subscribe to multiple topics by calling the subscribe method multiple times, allowing a single consumer to simultaneously subscribe to multiple topics. After reviewing the code of rocketmq-spring, specifically org.apache.rocketmq.spring.support.DefaultRocketMQListenerContainer, it appears that this approach is not supported.

最后使用RocketMQPushConsumerLifecycleListener实现,写在了一个消费类里,多次subscribe,gid一个应用一个是公司限制,不允许自己创建。

drpmma commented 3 months ago

可以将你的代码示例贴出来吗,这样别人碰到相同的问题看到你的issue也就可以解决了; 另外,group确实不应当和应用一对一绑定,可以是一个多对一的关系,从最佳实践来看,变更订阅关系的时候也是建议新建group来启用新的订阅关系

Can you post your code example? This way, others facing the same problem can find a solution when they see your issue. Additionally, it is indeed not advisable to bind a group one-to-one with an application; it can be a many-to-one relationship. From best practices, it is recommended to create a new group when changing subscription relationships to enable the new subscriptions.