【发布时间】:2017-07-30 06:42:33
【问题描述】:
我想知道当queue实际上是通过Spring Api在Rabbitmq中物理创建时是否发布了任何事件。
我问的原因是我们有竞争条件。 queue 的订阅通常需要更长的时间,并且在订阅发生时,已经从 BE 向此队列发送了一条消息,因此Rabbitmq 中不存在队列,并且消息丢失并且永远不会到达 FE。
对不起,我不能提供任何这样的代码,因为放一小段代码没有多大意义。
但我很确定,问题是由于某种竞争条件,发送到队列的消息甚至在创建之前就已发送。所以如果有一些event listener我可以在队列创建后监听,我可以将我的逻辑转移到这个方法。
这是一段代码,
stomp-client.js
stompClient.subscribe(destination, function(msg) {});
WebsocketConnectionListener.java
@EventListener
public void handleWebSocketSessionSubscribeEvent(final SessionSubscribeEvent event) {
// here I think this event is fired before the queue is actual created
// this event is fired when u send subscription from stomp-client.js
...
...
...
// trying to send message to this subscribed queue
simpMessagingTemplate.convertAndSend(TOPIC_PREFIX + destination, data, headers);
// now this message is lost as sometimes the queue creation takes longer.
// unfortunately I want to move the convert and send method, when I could listen to queue created event.
}
【问题讨论】:
标签: java spring events listener spring-rabbit