Java Spring集成-头丢失
我是Spring Integration和Spring Integration AMQP的新手 我有以下代码:Java Spring集成-头丢失,java,spring,spring-integration,spring-amqp,Java,Spring,Spring Integration,Spring Amqp,我是Spring Integration和Spring Integration AMQP的新手 我有以下代码: <bean id="enricher" class="soft.Enricher"/> <amqp:inbound-channel-adapter queue-names="QUEUE1" channel="amqpInboundChannel"/> <int:channel id="amqpInboundChannel"> <in
<bean id="enricher" class="soft.Enricher"/>
<amqp:inbound-channel-adapter queue-names="QUEUE1" channel="amqpInboundChannel"/>
<int:channel id="amqpInboundChannel">
<int:interceptors>
<int:wire-tap channel="logger"/>
</int:interceptors>
</int:channel>
<int:header-enricher input-channel="amqpInboundChannel" output-channel="routingChannel">
<int:header name="store" value="sj" />
</int:header-enricher>
<int:channel id="routingChannel" />
<int:header-value-router input-channel="routingChannel" header-name="store">
<int:mapping value="sj" channel="channelSJ" />
<int:mapping value="jy" channel="channelJY" />
</int:header-value-router>
<amqp:outbound-channel-adapter channel="channelSJ" exchange-name="ex_store" routing-key="sj" amqp-template="rabbitTemplate"/>
<amqp:outbound-channel-adapter channel="channelJY" exchange-name="ex_store" routing-key="jy" amqp-template="rabbitTemplate"/>
<int:channel id="channelSJ" />
<int:channel id="channelJY" />
<int:logging-channel-adapter id="logger" level="ERROR" />
设置如下所示:
一切正常,只是当入站通道适配器拾取消息时,消息头丢失
同样,当使用出站通道适配器将消息发送到exchange时,名为“store”的充实标头也会丢失
这是入站通道适配器拾取消息之前的外观:
这就是同一条消息处理整个过程的方式(注意没有标题)
我认为您的问题被描述为: “默认情况下,仅标准AMQP属性(例如contentType)将复制到Spring Integration MessageHeaders和从中复制。AMQP MessageProperties中的任何用户定义的头都不会复制到AMQP消息或从AMQP消息复制,除非通过此HeaderMapper的“requestHeaderNames”和/或“replyHeaderNames”属性显式标识。如果需要复制所有用户定义的头,只需使用通配符ch字符“”*“ 因此,您需要定义自己的
DefaultAmqpHeaderMapper
自定义实例,并使用它配置入站通道适配器。看
它可能看起来像这样:
<bean id="myHeaderMapper" class="org.springframework.integration.amqp.support.DefaultAmqpHeaderMapper">
<property name="requestHeaderNames" value="*"/>
<property name="replyHeaderNames" value="*"/>
</bean>
<amqp:inbound-channel-adapter queue-names="QUEUE1" channel="amqpInboundChannel"
header-mapper="myHeaderMapper"/>
我认为您的问题如下所述:
“默认情况下,仅标准AMQP属性(例如contentType)将复制到Spring Integration MessageHeaders和从中复制。AMQP MessageProperties中的任何用户定义的头都不会复制到AMQP消息或从AMQP消息复制,除非通过此HeaderMapper的“requestHeaderNames”和/或“replyHeaderNames”属性显式标识。如果需要复制所有用户定义的头,只需使用通配符ch字符“”*“
因此,您需要定义自己的DefaultAmqpHeaderMapper
自定义实例,并使用它配置入站通道适配器。看
它可能看起来像这样:
<bean id="myHeaderMapper" class="org.springframework.integration.amqp.support.DefaultAmqpHeaderMapper">
<property name="requestHeaderNames" value="*"/>
<property name="replyHeaderNames" value="*"/>
</bean>
<amqp:inbound-channel-adapter queue-names="QUEUE1" channel="amqpInboundChannel"
header-mapper="myHeaderMapper"/>
这只是基本的弹簧配置。没什么神奇的。但是我添加了一些应该与您想要的内容大致相同的内容。您也可以在adapapter上使用映射请求头=“*”。很高兴听到这个消息。祝你的项目好运!这只是基本的Spring配置。没什么神奇的。但是我添加了一些应该与您想要的内容大致相同的内容。您也可以在adapapter上使用映射请求头=“*”。很高兴听到这个消息。祝你的项目好运!