Pregunta

I'm new to Spring Integration and Spring Integration AMQP.

I have the following code:

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

The setup is the following:

My Setup

Everything is working fine except that headers are lost when a message is picked up by the inbound-channel-adapter.

Likewise the header being enriched called "store" is also lost when the message is being send to the exchange using the outbound-channel-adapter.

This is how a message is looking before being picked up by the inbound-channel-adapter:

Before

This is how the same message is looking after the whole process (notice no headers)

After

¿Fue útil?

Solución

I think your problem is described here:

"By default only standard AMQP properties (e.g. contentType) will be copied to and from Spring Integration MessageHeaders. Any user-defined headers within the AMQP MessageProperties will NOT be copied to or from an AMQP Message unless explicitly identified via 'requestHeaderNames' and/or 'replyHeaderNames' properties of this HeaderMapper. If you need to copy all user-defined headers simply use wild-card character ''.*"

So you need to define your own custom instance of DefaultAmqpHeaderMapper and configure the inbound-channel-adapter with it. See here.

It might look something like this:

        <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"/>
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top