java - rabbitmq 的同步发布
问题描述
我想有两组 API 供客户端发布消息
- 同步发送(不重试,立即失败并将状态同步发送回客户端)
- 异步发送(发布者和确认回调,重试,记录并在某些重试后删除消息)。我可以通过启用确认和返回来实现这一点。
有没有办法使用rabbitTemplate实现同步发布API,这将阻止确认并返回两者?
rabbiTemplate.waitForConfirmsOrDie(mills) 阻止确认,但我希望调用者知道路由是否也成功或抛出异常。
解决方案
请参阅以下 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
推荐阅读
- php - 如何使用两个插入查询从复选框循环两个值
- python - 如何在 python 中并行化包含发布请求 API 调用的 for 循环?
- session - express session值自动销毁
- excel - Excel 日期问题 - 将 Adobe PDF 保存为 XML 2003
- msal - msal angular 得到 ERROR 错误:未捕获(承诺中):错误:无法匹配任何路由。URL 段:'id_token'
- ajax - jQuery [attribute!=value] 选择器
- java - ThreadMXBean.getThreadCpuTime 返回 0
- c++ - 为表示一个或多个操作的 C++ 函数查找 int 参数的类型安全替换
- git - 在drupal 8中安装模块时作曲家抛出git错误
- typescript - 将类型分配给可能不需要解析的 JSON 类型