1.4 中自 1.3 以来的变化

@RabbitListener注解

POJO 侦听器可以用@RabbitListener,由@EnableRabbit<rabbit:annotation-driven />. 此功能需要 Spring Framework 4.1。 有关更多信息,请参阅 Annotation-driven Listener Endpointsspring-doc.cadn.net.cn

RabbitMessagingTemplate添加

新的RabbitMessagingTemplate允许您使用spring-messaging Message实例。 在内部,它使用RabbitTemplate,您可以正常配置。 此功能需要 Spring Framework 4.1。 有关更多信息,请参阅消息收发集成spring-doc.cadn.net.cn

侦听器容器missingQueuesFatal属性

1.3.5 引入了missingQueuesFatal属性SimpleMessageListenerContainer. 现在,这在侦听器容器命名空间元素上可用。 请参阅 消息侦听器容器配置spring-doc.cadn.net.cn

RabbitTemplate (兔模板)ConfirmCallback接口

confirmmethod 有一个名为cause. 如果可用,此参数包含否定确认 (nack) 的原因。 请参阅 相关发布者确认和返回spring-doc.cadn.net.cn

RabbitConnectionFactoryBean添加

RabbitConnectionFactoryBean创建底层 RabbitMQConnectionFactoryCachingConnectionFactory. 这允许使用 Spring 的依赖项注入配置 SSL 选项。 请参阅配置底层客户端连接工厂spring-doc.cadn.net.cn

CachingConnectionFactory

CachingConnectionFactory现在让connectionTimeout设置为命名空间中的属性或属性。 它在底层 RabbitMQ 上设置属性ConnectionFactory. 请参阅配置底层客户端连接工厂spring-doc.cadn.net.cn

Log Appender

Logback 软件org.springframework.amqp.rabbit.logback.AmqpAppender已引入。 它提供类似于org.springframework.amqp.rabbit.log4j.AmqpAppender. 有关更多信息,请参阅这些类的 JavaDoc。spring-doc.cadn.net.cn

The Log4jAmqpAppender现在支持deliveryMode属性 (PERSISTENTNON_PERSISTENT违约:PERSISTENT). 以前,所有 log4j 消息都是PERSISTENT.spring-doc.cadn.net.cn

appender 还支持修改Messagebefore sending — 例如,允许添加自定义标头。 子类应覆盖postProcessMessageBeforeSend().spring-doc.cadn.net.cn

侦听器队列

现在,默认情况下,侦听器容器会在启动期间重新声明任何缺失的队列。 新的auto-declare属性已添加到<rabbit:listener-container>来防止这些重新声明。 看auto-delete队列.spring-doc.cadn.net.cn

RabbitTemplate:mandatoryconnectionFactorySelector表达 式

mandatoryExpression,sendConnectionFactorySelectorExpressionreceiveConnectionFactorySelectorExpressionSpEL 表达式的属性已添加到RabbitTemplate. 这mandatoryExpression用于评估mandatoryboolean 值,当ReturnCallback正在使用中。 请参阅 相关发布者确认和返回。 这sendConnectionFactorySelectorExpressionreceiveConnectionFactorySelectorExpressionAbstractRoutingConnectionFactory,以确定lookupKey对于目标ConnectionFactory在每个 AMQP 协议交互作的运行时。 请参阅 Routing Connection Factoryspring-doc.cadn.net.cn

侦听器和路由连接工厂

您可以配置SimpleMessageListenerContainer使用路由连接工厂,以启用基于队列名称的连接选择。 请参阅 Routing Connection Factoryspring-doc.cadn.net.cn

RabbitTemplate:RecoveryCallback选择

recoveryCallback属性,以便在retryTemplate.execute(). 请参阅添加重试功能spring-doc.cadn.net.cn

MessageConversionException改变

此异常现在是AmqpException. 请考虑以下代码:spring-doc.cadn.net.cn

try {
    template.convertAndSend("thing1", "thing2", "cat");
}
catch (AmqpException e) {
	...
}
catch (MessageConversionException e) {
	...
}

第二个 catch 块不再可访问,需要移动到 catch-all 上方AmqpExceptioncatch 块。spring-doc.cadn.net.cn

RabbitMQ 3.4 兼容性

Spring AMQP 现在与 RabbitMQ 3.4 兼容,包括直接回复。 有关更多信息,请参阅兼容性RabbitMQ Direct 回复spring-doc.cadn.net.cn

ContentTypeDelegatingMessageConverter添加

ContentTypeDelegatingMessageConverter来选择MessageConverter使用,基于contentType属性在MessageProperties. 有关更多信息,请参阅 消息转换器spring-doc.cadn.net.cn