Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
hachikozjq opened this issue May 22, 2024 · 4 comments

Comments

@hachikozjq
Copy link

如题,有没有好的解决方案?
@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
Copy link
Contributor

drpmma commented May 23, 2024

最简单的解决方案,不要让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
Copy link
Contributor

drpmma commented May 23, 2024

在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
Copy link
Author

在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
Copy link
Contributor

drpmma commented May 24, 2024

可以将你的代码示例贴出来吗,这样别人碰到相同的问题看到你的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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants