出站消息转换
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
消息头设置为 application/json
会导致选择 JSON 转换器。
这适用于出站通道适配器和网关。
从 5.0 版本开始,添加到出站消息的 |