rocketmq-spring icon indicating copy to clipboard operation
rocketmq-spring copied to clipboard

Is it needed to separate producer and consumer in RocketMQAutoConfiguration

Open deanisty opened this issue 4 years ago • 7 comments

FEATURE REQUEST

image

RocketMQAutoConfiguration automatically imports ListenerContainerConfiguration and will start all consumers' listening threads after springboot starts. But in a normal project, I actually need to separate the producer and the consumer. They may be placed in two projects separately. At present, I have not found that the official code has the function of turning on/off the listener uniformly.

RocketMQAutoConfiguration 自动 import 了 ListenerContainerConfiguration 在 springboot 启动后会开启所有消费者的监听线程, 但是在正常项目中, 其实我是需要把 producer 和 consumer 分开的,可能是分别放在两个项目里面, 目前没有发现官方的代码里有统一开启/关闭 listener 的功能

deanisty avatar Mar 08 '21 09:03 deanisty

I think it is possible to create another autoconfiguration just for consumer like RocketMQListenerAutoConfiguration, this configuration only register and start consumer listener threads, is this more normal for decouple producers and consumers

deanisty avatar Mar 08 '21 09:03 deanisty

如果代码中没有实现RocketMQMessageListener 的annotation,是不会创建RocketMQListenerContainer的。

RongtongJin avatar Mar 08 '21 11:03 RongtongJin

如果代码中没有实现RocketMQMessageListener annotation的类,是不会创建RocketMQListenerContainer的。

RongtongJin avatar Mar 08 '21 11:03 RongtongJin

如果代码中没有实现RocketMQMessageListener 的annotation,是不会创建RocketMQListenerContainer的。

我现在是同一个项目同一套代码部署在两个集群,一个集群服务客户端http请求,一个集群专门处理后台脚本包括消息队列的消费者, 第一个集群我是不希望消费者启动过的,但是我找不到方法在第一个集群关掉consumer的 listener

deanisty avatar Mar 09 '21 01:03 deanisty

如果代码中没有实现RocketMQMessageListener 的annotation,是不会创建RocketMQListenerContainer的。

我现在是同一个项目同一套代码部署在两个集群,一个集群服务客户端http请求,一个集群专门处理后台脚本包括消息队列的消费者, 第一个集群我是不希望消费者启动过的,但是我找不到方法在第一个集群关掉consumer的 listener

这个解决了吗?我现在也遇到了这样的问题。springboot在启动时候回先去消费,而不是启动成功后再去消费。如果有大量的堆积mq,启动时候发现会特别慢。就是因为mq堆积导致在启动过程中先去消费造成的。

HappyDoyourself avatar Jul 15 '22 05:07 HappyDoyourself

如果代码中没有实现RocketMQMessageListener 的annotation,是不会创建RocketMQListenerContainer的。

我现在是同一个项目同一套代码部署在两个集群,一个集群服务客户端http请求,一个集群专门处理后台脚本包括消息队列的消费者, 第一个集群我是不希望消费者启动过的,但是我找不到方法在第一个集群关掉consumer的 listener

这个解决了吗?我现在也遇到了这样的问题。springboot在启动时候回先去消费,而不是启动成功后再去消费。如果有大量的堆积mq,启动时候发现会特别慢。就是因为mq堆积导致在启动过程中先去消费造成的。

我自己写了AOP并配合配置中心的配置,在不需要消费者的项目里统一把消费者取消注入了。 具体就是AOP切面切入 ListenerContainerConfiguration.afterSingletonsInstantiated() 方法,然后around()方法不做任何操作直接返回void,以此达到不注入所有用RocketMQMessageListener注解的消费者实例,切面类本身用外部配置配合ConditionalOnProperty注解控制,可以实现用不同的配置打开或者关闭这个AOP的功能。

deanisty avatar Jul 15 '22 09:07 deanisty

我还没实现。我的思路是通过实现BeanFactory、ApplicationRunner,尝试启动时候先不注入spring容器,想要通过spring的监听来达到同样的效果。但是我看了RocketMQAutoConfiguration源码里面是通过import引入的,只要有RocketMQMessageListener的注解,都会注入到容器,所以启动时候就就自动去加载。这就和我想通过监听重复了。目前也没有更好的思路。我想想按照你的思路怎么实现吧。Thanks

HappyDoyourself avatar Jul 15 '22 09:07 HappyDoyourself