此版本仍在开发中,尚未被视为稳定版本。对于最新的稳定版本,请使用 Spring AMQP 3.2.0spring-doc.cadn.net.cn

自 2.1 以来 2.2 中的变化

本节介绍版本 2.1 和版本 2.2 之间的更改。spring-doc.cadn.net.cn

套件更改

以下类/接口已从org.springframework.amqp.rabbit.core.supportorg.springframework.amqp.rabbit.batch:spring-doc.cadn.net.cn

另外ListenerExecutionFailedException已从org.springframework.amqp.rabbit.listener.exceptionorg.springframework.amqp.rabbit.support.spring-doc.cadn.net.cn

依赖项更改

JUnit (4) 现在是可选依赖项,将不再显示为传递依赖项。spring-doc.cadn.net.cn

spring-rabbit-junitmodule 现在是spring-rabbit-test模块,以获得更好的目标应用程序开发体验,而此时只有一个spring-rabbit-test我们获得了 AMQP 组件的完整测试实用程序堆栈。spring-doc.cadn.net.cn

[[-breaking-api-changes]] == “Breaking” API 更改spring-doc.cadn.net.cn

JUnit (5)RabbitAvailableCondition.getBrokerRunning()现在返回一个BrokerRunningSupport实例而不是BrokerRunning,它依赖于 JUnit 4。 它具有相同的 API,因此只需更改任何引用的类名即可。 有关更多信息,请参阅 JUnit5 条件spring-doc.cadn.net.cn

ListenerContainer 更改

默认情况下,具有致命异常的消息现在会被拒绝并且不会重新排队,即使确认模式是手动的。 有关更多信息,请参阅异常处理spring-doc.cadn.net.cn

现在可以使用 Micrometer 监控侦听器性能Timers. 有关更多信息,请参阅监控侦听器性能spring-doc.cadn.net.cn

@RabbitListener 更改

现在,您可以配置executor在每个侦听器上,覆盖出厂配置,以便更轻松地识别与侦听器关联的线程。 您现在可以覆盖容器工厂的acknowledgeMode属性与注解的ackMode财产。 有关更多信息,请参阅覆盖 Container Factory 属性spring-doc.cadn.net.cn

使用批处理时,@RabbitListener方法现在可以在一次调用中接收一批完整的消息,而不是一次获取一条消息。spring-doc.cadn.net.cn

当一次接收一条批量消息时,最后一条消息具有isLastInBatchmessage 属性设置为 true。spring-doc.cadn.net.cn

此外,收到的批处理消息现在包含amqp_batchSize页眉。spring-doc.cadn.net.cn

侦听器还可以使用在SimpleMessageListenerContainer,即使该批次不是由生产者创建的。 有关更多信息,请参阅选择容器spring-doc.cadn.net.cn

Spring Data Projection 接口现在由Jackson2JsonMessageConverter. 有关更多信息,请参见使用 Spring Data Projection 接口spring-doc.cadn.net.cn

Jackson2JsonMessageConverter现在假设内容为 JSON,如果没有contentType属性,或者它是默认的 (application/octet-string). 看Message了解更多信息。spring-doc.cadn.net.cn

同样地。这Jackson2XmlMessageConverter现在假定内容为 XML(如果没有contentType属性,或者它是默认的 (application/octet-string). 看Jackson2XmlMessageConverter了解更多信息。spring-doc.cadn.net.cn

@RabbitListener方法返回一个结果,则 bean 和Method现在在 reply message 属性中可用。 这允许配置beforeSendReplyMessagePostProcessor例如,在回复中设置一个 Headers 以指示在服务器上调用了哪个方法。 有关更多信息,请参阅回复管理spring-doc.cadn.net.cn

您现在可以配置ReplyPostProcessor在发送回复消息之前对其进行修改。 有关更多信息,请参阅回复管理spring-doc.cadn.net.cn

AMQP 日志记录附加程序更改

Log4J 和 LogbackAmqpAppender现在支持verifyHostnameSSL 选项。spring-doc.cadn.net.cn

此外,这些 appender 现在可以配置为不将 MDC 条目添加为 headers。 这addMdcAsHeadersboolean 选项来配置此类行为。spring-doc.cadn.net.cn

appender 现在支持SaslConfig财产。spring-doc.cadn.net.cn

MessageListenerAdapter 更改

MessageListenerAdapter现在提供了一个新的buildListenerArguments(Object, Channel, Message)方法来构建要传递到 Target 侦听器的参数数组,并且旧的参数数组已弃用。 看MessageListenerAdapter了解更多信息。spring-doc.cadn.net.cn

[[交换/队列声明更改]] == Exchange/Queue 声明更改spring-doc.cadn.net.cn

ExchangeBuilderQueueBuilder用于创建的 Fluent APIExchangeQueue声明对象RabbitAdmin现在支持 “众所周知” 参数。 有关更多信息,请参阅适用于 Queues 和 Exchanges 的 Builder APIspring-doc.cadn.net.cn

RabbitAdmin具有新属性explicitDeclarationsOnly. 有关更多信息,请参阅 条件声明spring-doc.cadn.net.cn

连接工厂更改

CachingConnectionFactory具有新属性shuffleAddresses. 在提供代理节点地址列表时,该列表将在创建连接之前随机排列,以便尝试连接的顺序是随机的。 有关更多信息,请参阅连接到集群spring-doc.cadn.net.cn

现在,当使用 Publisher 确认并返回时,回调会在连接工厂的executor. 这避免了amqp-clientslibrary 中执行 rabbit作。 有关更多信息,请参阅 Correlated Publisher Confirms and Returnsspring-doc.cadn.net.cn

此外,发布者确认类型现在使用ConfirmTypeenum 而不是两个互斥的 setter 方法。spring-doc.cadn.net.cn

RabbitConnectionFactoryBean现在,启用 SSL 时,默认使用 TLS 1.2。 看RabbitConnectionFactoryBean和配置 SSL了解更多信息。spring-doc.cadn.net.cn

新的 MessagePostProcessor 类

DeflaterPostProcessorInflaterPostProcessor分别添加了以支持压缩和解压缩,当消息 content-encoding 设置为deflate.spring-doc.cadn.net.cn

其他更改

Declarablesobject(用于声明多个队列、交换、绑定)现在每种类型都有一个过滤的 getter。 有关更多信息,请参见Declaring Collections of Exchanges, Queues, and Bindingsspring-doc.cadn.net.cn

您现在可以自定义每个Declarablebean 之前的RabbitAdmin处理其声明。 有关更多信息,请参见 Automatic Declaration of Exchanges, Queues, and Bindingsspring-doc.cadn.net.cn

singleActiveConsumer()已添加到QueueBuilder要设置x-single-active-consumerqueue 参数。 有关更多信息,请参阅适用于 Queues 和 Exchanges 的 Builder APIspring-doc.cadn.net.cn

值为Class<?>现在使用getName()而不是toString(). 有关更多信息,请参阅 消息属性转换器spring-doc.cadn.net.cn

现在支持恢复失败的创建者创建的批处理。 有关更多信息,请参阅使用 Batch 侦听器重试spring-doc.cadn.net.cn