question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Is it needed to separate producer and consumer in RocketMQAutoConfiguration

See original GitHub issue

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 的功能

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
deanistycommented, Jul 15, 2022

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

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

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

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

0reactions
HappyDoyourselfcommented, Jul 15, 2022

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Use rocketmq-spring-boot-starter to Configure, Send, and ...
The spring-boot-starter will be encapsulated separately on the producer and the consumer. In the current implementation, a compatible method is ...
Read more >
Spring Tips: Apache RocketMQ
Let's look at a simple producer class that uses the Spring Boot autoconfiguration and the RocketMQTemplate . In order to work with this,...
Read more >
Basic Best Practices - RocketMQ
This section describes the behavior configuration common to producers and consumers.
Read more >
rocketmq-spring/RocketMQAutoConfiguration.java at master
java. This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Read more >
Spring Tips: Apache RocketMQ - DZone Java
You'll need to use Java 8 when running Apache RocketMQ. (You can use any version of Java when writing Spring applications that connect...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found