spring-projects / spring-integration

Spring Integration provides an extension of the Spring programming model to support the well-known Enterprise Integration Patterns (EIP)
http://projects.spring.io/spring-integration/
Apache License 2.0
1.54k stars 1.1k forks source link

Round Tripping AMQP headers through the inboud and outbound adapters doesn't seem to work [INT-2296] #6243

Closed spring-operator closed 12 years ago

spring-operator commented 12 years ago

Josh Long opened INT-2296 and commented

The gist of it is :

I'm sending a message to Rabbit using the Spring AMQP outbound adapter and I expect the headers that are in the message to be in the message when the message pops out the other end and is consumed by the AMQP inbound channel adapter.

   <integration:gateway service-interface="org.springframework.samples.travel.services.integration.NotificationGateway" 
      default-request-channel="enqueuedEmails" />

    <int-amqp:outbound-channel-adapter
            channel="enqueuedEmails"
            exchange-name="${amqp.notification.exchange}"
            routing-key="${amqp.notification.exchange}"
            amqp-template="rabbitTemplate"
            mapped-request-headers="*"
            />

The code for the gateway is:

public interface NotificationGateway {
    void sendNotification(
            @Header(MailHeaders.TO) String destinationAddresses,
            @Header(MailHeaders.SUBJECT) String subject,
            @Payload Map<String, String> body);

}

So the messages are sent with headers (MailHeaders.TO, and MailHeaders.SUBJECT) that should be there in the message on the broker.

Then, on the other end≤ I have:

<int-amqp:inbound-channel-adapter
        channel="dequeuedEmails"
        queue-names="${amqp.notification.queue}"
        connection-factory="connectionFactory"
        acknowledge-mode="AUTO"
        message-converter="jsonMessageConverter"
        mapped-request-headers="*"
    /> 

Then I had a service activator and i stuck a break point there and it didn't have the headers (MailHeaders.TO, and MailHeaders.SUBJECT) anywhere to be found.

I tried various incantations of the mapped-request-headers, finally deciding to just use * to let everything through, but clearly it's not working...


Affects: 2.1 RC1

spring-operator commented 12 years ago

Gary Russell commented

Hmmm... works ok for me on a modified version of the amqp sample...

<!-- From STDIN To RabbitMQ -->

<int-stream:stdin-channel-adapter id="consoleIn" channel="toHE" >
    <int:poller fixed-delay="1000" max-messages-per-poll="1" />
</int-stream:stdin-channel-adapter>

<int:channel id="toRabbit" />

<int:header-enricher input-channel="toHE" output-channel="toRabbit">
    <int:header name="xyz" value="abc"/>
    <int:header name="def" value="ghi"/>
</int:header-enricher>

<int-amqp:outbound-channel-adapter channel="toRabbit"
        amqp-template="amqpTemplate" exchange-name="si.test.exchange" 
        routing-key="si.test.binding"
        mapped-request-headers="xyz, def"/>

<!-- From RabbitMQ To STDOUT -->

<int-amqp:inbound-channel-adapter channel="fromRabbit" 
                                  queue-names="si.test.queue"
                                  mapped-request-headers="xyz, def"
                                  connection-factory="connectionFactory" />

<int:channel id="fromRabbit">
    <int:interceptors>
        <int:wire-tap channel="loggingChannel"/>
    </int:interceptors>
</int:channel>
Received message: (Body:'zzz'; ID:null; Content:text/plain; Headers:{def=ghi, xyz=abc}; Exchange:si.test.exchange; RoutingKey:si.test.binding; Reply:null; DeliveryMode:PERSISTENT; DeliveryTag:1) 

headerName=[def] WILL be mapped, matched pattern=def
headerName=[xyz] WILL be mapped, matched pattern=xyz 

preSend on channel 'fromRabbit', message: [Payload=zzz][Headers={timestamp=1323213036622, id=1e532949-99b5-4b87-b344-14fb0bece737, def=ghi, xyz=abc}] 

Josh, can you attach a debug log?

spring-operator commented 12 years ago

Mark Fisher commented

Josh, it's not clear to me from reading the comment above, are you saying that it DOES work when you provide "*"?

spring-operator commented 12 years ago

Josh Long commented

No, in my particular example it didn't seem to work, but clearly I've misconfigured ...something.. if the above works as expected. Please ignore, and I'm sorry for the trouble.

spring-operator commented 12 years ago

Mark Fisher commented

Okay. If you run into any situation in the future, please re-open this issue. I'll resolve it for now.