1

我是 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" />

设置如下:

我的设置

一切工作正常,除了入站通道适配器接收消息时标头丢失。

同样,当使用 outbound-channel-adapter 将消息发送到交换器时,称为“存储”的被丰富的标头也会丢失。

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

前

这就是同一条消息在整个过程中的处理方式(注意没有标题)

后

4

1 回答 1

8

我认为您的问题在这里描述:

"默认情况下,只会将标准 AMQP 属性(例如 contentType)复制到 Spring Integration MessageHeaders 或从其中复制。除非通过“requestHeaderNames”和/或此 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"/>
于 2013-11-02T15:22:19.723 回答