4
votes

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

3
Just take a look at what other headers is thereClaus Ibsen
I did already: breadcrumbId=xxx CamelAwsSqsAttributes={} CamelAwsSqsMD5OfBody=yyy CamelAwsSqsMessageAttributes={} CamelAwsSqsMessageId=zzz CamelAwsSqsReceiptHandle=aaa (xxx, yyy, zzz and aaa are just replacements of course)Maxime Laval

3 Answers

5
votes

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.

2
votes

I faced the same issue. When I am using camel-aws 2.16.x and I have my endpoint configured as follow

from("aws-sqs://myQueue?...&messageAttributeNames=#sqsMsgAttributeNames")
    .to(...)

Then I have defined a Collection of String in my spring configuration file

@Bean
public Collection<String> sqsMsgAttributeNames() {
     return Arrays.asList("Attr1", "Attr2");
}

Above settings work fine but ever since I upgraded to camel-aws 2.17.3. It no longer works. As mentioned in Camel SQS Component, collection of string no longer will be supported for messageAttributeNames and it should be a String with attributes separated by comma.

Note: The string containing attributes should not contain any white spaces otherwise camel-aws component will only read the first attribute. I went through the pain to debug on this. Besides, setting the attribute value to be "All" does not work for me, none of the message attributes will be read.

Below is the changes I made that allowed camel-aws's SqsConsumer to work again:

@Bean
public String sqsMsgAttributeNames() {
     return String.format("%s,%s", "Attr1", "Attr2");
}
1
votes

It is not an issue of Camel. It can be the default behavior of SQS or aws-java-sdk-core library. As a quick solution this aws-sqs URL can be used

aws-sqs://myQueue?<other attributes here>&attributeNames=All

Keep in mind that localstack can work well without attributeNames parameter, unlike SQS.