Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot delete Message from SQS Camel Route

i recently had a question about AWS and Camel but finally i fought my way through. Now the application seems to work however i am getting a very strange exception.

First of all my App is divided in two EC2 Instances. Instance one gets the ISBN of the top 10 books from an Amazon RSS Feed and stores it into an. Here is the Code Snippet.

    public static void main(String[] args) throws Exception {

    CamelContext context = new DefaultCamelContext();
    context.addRoutes(new RouteBuilder() {
        public void configure() {

            from(
                    "rss:http://www.amazon.de/gp/rss/bestsellers/books/ref=zg_bs_books_rsslink?splitEntries=false")
                    .split()
                    .method("RssSplitter", "split")
                    .process(new Dummy())
                    .setProperty("isbn", simple("${body}"))
                    .to("aws-sqs://bookz_sqs?accessKey=acceskey&secretKey=secretKey");

        }
    });
    context.start();
    Thread.sleep(10000);
    context.stop();

}

Instance two is responsible for reading out the SQS as first operation and finally get additional Book information from oder Booklibraries in the WWW what is no problem, and finally build a RSS Feeder which was no problem too.

public static void main(String[] args) throws Exception {
    /*
     * Here the sqs camel route gets the ISBN out of the queues and stores it in S3.
     */
    CamelContext context = new DefaultCamelContext();
    context.addRoutes(new RouteBuilder() {
        public void configure() {
            from("aws-sqs://bookz_sqs" + "?accessKey=accessKey" + "&secretKey=secretKey").process(new DynamicIsbnEnrich()).process(
                    new DynamicIsbndbEnrich()).process(new DynamicOpLibEnrich()).setHeader(S3Constants.KEY, simple("${property.isbn}")).to(
                    "aws-s3://bookz" + "?accessKey=accesKey" + "&secretKey=secretKEy" + "&region=eu-west-1");

        }
    });
    context.start();
    Thread.sleep(10000);
    context.stop();
}

The problem is now the strange exception, which i dont understand and besides SQS is NOT deleting the messages from my queue , however the api sais that the deleteAfter Read is on true by default.

2012-12-17 19:45:08,335 [Camel (camel-1) thread #0 - aws-sqs://team09bookz_sqs] WARN org.apache.camel.component.aws.sqs.SqsConsumer - Error occurred during deleting message.. Caused by: [com.amazonaws.AmazonServiceException - The request must contain the parameter MessageHandle.] Status Code: 400, AWS Service: AmazonSQS, AWS Request ID: 0655aa05-ad6f-5571-a83d-e34cc7196343, AWS Error Code: MissingParameter, AWS Error Message: The request must contain the parameter MessageHandle.

The application works but i cant delete any messages in the queue and i dont know why, do i require some additional security credentials ?

Anyhow thanks for help

like image 556
Maevy Avatar asked Dec 17 '12 19:12

Maevy


2 Answers

This error is caused by a null value for the message handle that the Camel SQS endpoint does not find in the output headers. Probably a check should be added and a warning logged when this happens...

To solve, you must ensure that headers set by the SQS producer are passed along all to the end of the route: if you set a new header somewhere, you must also copy the ones from the input, otherwise they are lost.

like image 56
Andrea Ratto Avatar answered Nov 24 '22 07:11

Andrea Ratto


I wasn't sure how the above would be implemented so this piece of code grabs the Header required and sets it back up at the end.

from("aws-sqs://aqueue")
.setProperty(SqsConstants.RECEIPT_HANDLE, header(SqsConstants.RECEIPT_HANDLE))

...

.setHeader(SqsConstants.RECEIPT_HANDLE, exchangeProperty(SqsConstants.RECEIPT_HANDLE));
like image 42
Michael Willis Avatar answered Nov 24 '22 06:11

Michael Willis