Spring Integration - 标题丢失了

Emi*_*l C 1 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">
    <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" />
Run Code Online (Sandbox Code Playgroud)

设置如下:

我的设置

一切正常,但是当入站通道适配器拾取消息时,标题会丢失.

同样,当使用出站通道适配器将消息发送到交换机时,被称为"存储"的标题也被丢失.

这是消息在被入站通道适配器拾取之前的样子:

之前

这是同一条消息在整个过程中的注意事项(注意没有标题)

后

Vid*_*dya 8

我想你的问题在这里描述:

" 默认情况下,只有标准AMQP属性(例如contentType)将被复制到Spring Integration MessageHeaders和从Spring Integration MessageHeaders复制.除非通过'requestHeaderNames'和/或明确标识,否则AMQP MessageProperties中的任何用户定义的头都不会被复制到AMQP消息或从AMQP消息复制.此HeaderMapper的'replyHeaderNames'属性.如果您需要复制所有用户定义的标题,只需使用通配符' '.*"

因此,您需要定义自己的自定义实例DefaultAmqpHeaderMapperinbound-channel-adapter使用它进行配置.看到这里.

它可能看起来像这样:

        <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"/>
Run Code Online (Sandbox Code Playgroud)