领先一步
VMware 提供培训和认证来加速您的进步。
了解更多我们很高兴宣布 Spring AMQP 1.4 的候选版本发布;GA 计划于 11 月初发布。
首先,感谢大家为 1.4 M1 里程碑版本提供反馈并提交报告(错误或新功能)。特别感谢 Stéphane Nicoll,他引入了基于注解的消息监听器 (@RabbitListener) 和新的 RabbitMessagingTemplate。
@SendTo 注解将方法的结果作为回复消息发送(当入站消息中没有 replyTo 时)@RabbitListener(queues = "capitalize")
@SendTo("capitalize.reply")
public String capitalize(String s) {
return s.toUpperCase();
}
(基于注解的监听器需要 Spring Framework 4.1.x)。
引入了新的 RabbitMessagingTemplate,允许使用 spring-messaging Message<?> 抽象作为 Spring AMQP Message 的替代方案(注解监听器也支持 Spring Messaging Message<?>)。
现在可以使用 Logback AmqpAppender,其配置与现有的 Log4j AmqpAppender 类似
<appender name="AMQP" class="org.springframework.amqp.rabbit.logback.AmqpAppender">
<layout>
<pattern><![CDATA[ %d %p %t [%c] - <%m>%n ]]></pattern>
</layout>
<abbreviation>36</abbreviation>
<applicationId>MyApplication</applicationId>
<routingKeyPattern>%property{applicationId}.%c.%p</routingKeyPattern>
<generateId>true</generateId>
<charset>UTF-8</charset>
<durable>false</durable>
<deliveryMode>NON_PERSISTENT</deliveryMode>
</appender>
expression 属性的 AbstractRoutingConnectionFactory 配置 RabbitTemplate,以根据 RabbitTemplate 操作确定目标 ConnectionFactory<rabbit:template connection-factory="RoutingConnectionFactory"
send-connection-factory-selector-expression="messageProperties.userId"
receive-connection-factory-selector-expression="#root == 'fooQueue' ? 'foo' : null"/>
mandatory-expression 属性已添加到 RabbitTemplate,用于为每个发送的消息设置 mandatory 标志<rabbit:template connection-factory="connectionFactory"
mandatory-expression="messageProperties.contentType == 'application/json'"/>
(以前,mandatory 在模板级别设置)。
AbstractRoutingConnectionFactory 现在也支持 MessageListenerContainer,其中 key 用于目标 ConnectionFactory 基于配置的 queueNames 数组