Why aws-sqs component unable to retrieve headers when consuming message from queue ?

Solution Verified - Updated -

Environment

  • Red Hat JBoss Fuse
    • 6.2.1

Issue

  • The sqs component doesn't retrieve message headers properly from SQS.
  • The producer is sending the message with headers. However, headers are not there once a message is consumed.

Resolution

  • Following is an example where in first route one can send header to aws-sqs and in another route it can be consumed using messageAttributeNames.
  <bean id="allArgs" class="com.example.AllAttributesList" />

  <camelContext trace="false" xmlns="http://camel.apache.org/schema/blueprint">
    <route id="toSQS">
      <from uri="file:///tmp?autoCreate=false&amp;fileName=foo"/>

      <setHeader headerName="MyTestHeader">
        <constant>TestHeader</constant>
      </setHeader>

      <to uri="aws-sqs://test-queue?amazonSQSClient=#sqsClient"/>
    </route>

    <route id="fromSqs">
      <from uri="aws-sqs://test-queue?amazonSQSClient=#sqsClient&amp;messageAttributeNames=#allArgs"/>
      <log message="ALL HEADERS: ${headers}"/>
      <log message="HEADER: ${headers.MyTestHeader}"/>
    </route>
  </camelContext>
  • Above AllAttributeList class with All attributes can be written following way
package com.example;

import java.util.ArrayList;

public class AllAttributesList extends ArrayList<String> {

    public AllAttributesList() {
        super();
        add("All");
    }
}

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.

Close

Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.