Announcement Announcement Module
Collapse
No announcement yet.
Spring Integration + RabbitmQ Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring Integration + RabbitmQ

    Hello,

    I have two separate apps:
    App1: Uses RabbitMQ client to send message to RabbitMQ broker.
    - The message is a JSON object.
    - The JSON contains a single property named "DATA" which is also a JSON object.
    - I also add 2 additional headers (ID,ENDPOINT).
    - The message needs to be transformed to byte[] prior to sending (according to RabbitMQ API).

    App2: Uses Spring Integration to get the messages sent from App1 and store them in DB. The DB table contains the 3 columns, to be populated from the message data, as shown below:
    - ID column value : from header[ID]
    - ENDPOINT column value : from header[ENDPOINT]
    - DATA column value : from payload[DATA]

    Issues:
    1. The 2 headers exist on RabbitMQ project but when the message arrives in my Spring Integration app (App2) are not there (I get null value). The query used to enter the data in DB (via a jdbc outbound adapter) is the following:
    Code:
    insert into my_table (id,endpoint,data) values(:headers[ID],:headers[ENDPOINT],:payload[DATA])
    However the 2 header values are not present and I get an exception (as ID is a PK). Is this expected behavior?

    2. If I use a transformer,converter or deserializer (so the original message is converted to an object, or String or...), are the headers maintained in the message (aka the conversion only affects the payload)?

    Best regards

  • #2
    Hi!

    You have to use 'header-mapper' on the amqp:inbound-adpter:
    HTML Code:
    <amqp:inbound-channel-adapter queue-names="YOUR_QUEUE"
                    channel="YOUR_CHANNEL"
                    mapped-request-headers="ID,ENDPOINT"/>
    Or just use "*" instead of header names.

    Take care,
    Artem

    Comment


    • #3
      If you also need any standard Rabbit headers (redelivered etc), you also need to include the token 'STANDARD_REQUEST_HEADERS' in the mapped-request-headers attribute (this is the default if no mapped-request-headers attribute exists).

      If App1 is Spring Integration too, mapping needs to occur on the outbound side as well.

      Comment

      Working...
      X