[英]Get message by id from RabbitMQ
I'm using RabbitMQ with Spring AMQP. 我正在将RabbitMQ与Spring AMQP结合使用。 I want to send some message to the MQ and then obtain just this one (by ID or something).
我想向MQ发送一些消息,然后仅获取此消息(通过ID或其他方式)。
Right now I have a listener which receives every message sent to MQ: 现在,我有一个侦听器,它接收发送给MQ的每条消息:
val latch = CountDownLatch(1)
@RabbitListener(queues = arrayOf(RabbitMqConfig.QUEUE_NAME))
fun receiveMessage(message: Message) {
logger.info("Received message with body = ${message.body}")
latch.countDown()
}
But how can I get specific message by id? 但是如何通过ID获取特定消息? I've read about correlationId but there's no method in the RabbitTemplate class to receive by correlationId.
我已经阅读了相关ID,但是RabbitTemplate类中没有任何方法可以通过相关ID接收。
There is also an AsyncRabbitTemplate
which returns a ListenableFuture<?>
when calling one of its sendAndReceive
methods. 还有一个
AsyncRabbitTemplate
,当调用其sendAndReceive
方法之一时,它返回ListenableFuture<?>
。
When the async reply is received, you can store the state in your rest controller (or a database) and the user can query the state. 收到异步答复后,您可以将状态存储在rest控制器(或数据库)中,用户可以查询状态。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.