此版本仍在开发中,尚不被认为是稳定的。对于最新的稳定版本,请使用 Spring Integration 6.5.1! |
出站消息转换
Spring AMQP 1.4 引入了ContentTypeDelegatingMessageConverter
,其中实际转换器是根据
在传入内容类型消息属性上。
这可以由入站端点使用。
从 Spring Integration 4.3 版本开始,您可以使用ContentTypeDelegatingMessageConverter
在出站端点上,使用contentType
标头,指定使用哪个转换器。
以下示例配置ContentTypeDelegatingMessageConverter
,默认转换器是SimpleMessageConverter
(处理 Java 序列化和纯文本),以及 JSON 转换器:
<amqp:outbound-channel-adapter id="withContentTypeConverter" channel="ctRequestChannel"
exchange-name="someExchange"
routing-key="someKey"
amqp-template="amqpTemplateContentTypeConverter" />
<int:channel id="ctRequestChannel"/>
<rabbit:template id="amqpTemplateContentTypeConverter"
connection-factory="connectionFactory" message-converter="ctConverter" />
<bean id="ctConverter"
class="o.s.amqp.support.converter.ContentTypeDelegatingMessageConverter">
<property name="delegates">
<map>
<entry key="application/json">
<bean class="o.s.amqp.support.converter.Jackson2JsonMessageConverter" />
</entry>
</map>
</property>
</bean>
将消息发送到ctRequestChannel
使用contentType
header 设置为application/json
导致选择 JSON 转换器。
这适用于出站通道适配器和网关。
从 5.0 版开始,添加到 但是,在某些情况下,需要以前的行为——例如,当 现在有一个名为 从 5.1.9 版本开始,类似的 |