Search code examples
apache-camelamazon-sqs

Camel doesn't retrieve SQS messages attributes


Here is the route:

from("aws-sqs://myQueue?accessKey=RAW(xxx)&secretKey=RAW(yyy)&deleteAfterRead=false")
.log("Attributes: ${header.CamelAwsSqsAttributes}")
.process(new Processor() {
    @Override
    public void process(Exchange exchange) throws Exception {
        Map<String, String> messageAttributes = (Map<String, String>) exchange.getIn().getHeader("CamelAwsSqsAttributes");
        ...
    }
});

The .log() shows an empty map as well as if I print messageAttributes from the processor.

I also tried with the header "CamelAwsSqsMessageAttributes" instead of "CamelAwsSqsAttributes" but still nothing.

I see the attributes from the AWS console though.
By the way I get the message body, and I use Camel 2.15


Solution

  • I figured it out, here is an example to get queue attributes and message attributes:

    main.bind("sqsAttributeNames", Collections.singletonList("All"));
    main.bind("sqsMessageAttributeNames", Collections.singletonList("All"));
    

    Or add those objects to the registry if you don't use org.apache.camel.main.Main
    Then:

    from("aws-sqs://myQueue?accessKey=RAW(xxx)&secretKey=RAW(yyy)&deleteAfterRead=false&attributeNames=#sqsAttributeNames&messageAttributeNames=#sqsMessageAttributeNames")
    

    Of course you can replace Collections.singletonList("All") with the list of attributes you need if you don't want all of them.