首页 > 解决方案 > rabbitmq 的同步发布

问题描述

我想有两组 API 供客户端发布消息

有没有办法使用rabbitTemplate实现同步发布API,这将阻止确认并返回两者?

rabbiTemplate.waitForConfirmsOrDie(mills) 阻止确认,但我希望调用者知道路由是否也成功或抛出异常。

标签: javaspringjunitspring-amqpspring-rabbit

解决方案


请参阅以下 API RabbitOeprations

/**
 * Send a message to a specific exchange with a specific routing key.
 *
 * @param exchange the name of the exchange
 * @param routingKey the routing key
 * @param message a message to send
 * @param correlationData data to correlate publisher confirms.
 * @throws AmqpException if there is a problem
 */
void send(String exchange, String routingKey, Message message, CorrelationData correlationData)

return 或confirm 设置在所提供的最后CorrelationData。您必须等待它getFuture(),然后将您做出的Confirm不合理的决定返回给调用者。CorrelationData在该JavaDocs 及其实现中查看更多信息。另请参阅有关此事的一些文档:https ://docs.spring.io/spring-amqp/docs/current/reference/html/#template-confirms


推荐阅读