Spring Boot应用不消耗队列消息
我有兔子MQ经纪人在服务之间进行异步传达。 服务正在将消息发送到队列。我检查了队列,服务A的消息到达:
我正在尝试在服务B 中创建一个听众,以消耗服务A。它似乎已成功联系在一起。
问题是服务B成功开始,但它正在接收兔子MQ的消息。
以下是侦听器的实现:
@Slf4j
@Component
public class EventListener {
public static final String QUEUE_NAME = "events";
@RabbitListener(
bindings = {
@QueueBinding(
value = @Queue(QUEUE_NAME),
exchange = @Exchange("exchange")
)
}
)
public void handleTaskPayload(@Payload String payload) {
System.out.println(payload);
}
}
我验证了兔子MQ中的队列和交换信息,它们是正确的。
一切正常工作,并且在服务A或服务B中没有错误的错误,这使此问题更难调试。
我试图从RabbitMQ的队列GetMessage中检索消息,如下所示:
{"id":"1",:"name:"Test","created":null}
感谢您对解决此问题的任何帮助或指导。
此致, 兰多。
ps
i创建了一个新的测试队列,如以下内容,并发布了一些消息:
如下所示,仍然无法触发侦听器来收听侦听器队列事件:
@Slf4j
@Component
public class RobotRunEventListener {
public static final String QUEUE_NAME = "test";
@RabbitListener(
bindings = {
@QueueBinding(
value = @Queue(QUEUE_NAME),
key = "test",
exchange = @Exchange("default")
)
}
)
public void handleTaskPayload(@Payload String payload) {
System.out.println(payload);
}
I have the Rabbit MQ broker for communicating asynchronously between services. Service A is sending messages to the queue. I checked the queue and the messages from Service A have arrived:
I am trying to create a listener in the Service B in order to consume the messages produced by Service A. I verified like below to check if Service B is connected with RabbitMQ and it seems to be connected successfully.
The problem is that Service B started successfully but it is receiving messages from Rabbit MQ.
Below is the implementation of the listener:
@Slf4j
@Component
public class EventListener {
public static final String QUEUE_NAME = "events";
@RabbitListener(
bindings = {
@QueueBinding(
value = @Queue(QUEUE_NAME),
exchange = @Exchange("exchange")
)
}
)
public void handleTaskPayload(@Payload String payload) {
System.out.println(payload);
}
}
I verified the queue and exchange information in the Rabbit MQ and they are correct.
Everything is working correctly and there is no error thrown in service A or service B which makes this problem much harder to debug.
I tried to retrieve the message from the queue getMessage of RabbitMQ the message is like the below:
{"id":"1",:"name:"Test","created":null}
I will appreciate any help or guidance towards the solution of this problem.
Best Regards,
Rando.
P.S
I created a new test queue like the below and published some messages:
Modified the listener code like below and still wasn't able to trigger listener to listen to the queue events:
@Slf4j
@Component
public class RobotRunEventListener {
public static final String QUEUE_NAME = "test";
@RabbitListener(
bindings = {
@QueueBinding(
value = @Queue(QUEUE_NAME),
key = "test",
exchange = @Exchange("default")
)
}
)
public void handleTaskPayload(@Payload String payload) {
System.out.println(payload);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试这种方法:
Try this approach:
问题是我正在使用的Spring Boot应用程序具有
@conditional(config.class)
,该应用程序阻止了下面的BEAN创建:这导致Spring Boot应用程序未听兔子MQ事件。 config.class需要一个特定的配置文件,以使应用程序能够收听兔子MQ事件。
The problem was that the spring boot app that I was working on had a
@Conditional(Config.class)
that prevented the creation of the bean below:which resulted in the spring boot app not listening to Rabbit MQ events. The Config.class required a specific profile in order to enable the app to listen to Rabbit MQ events.