Resending messages at some point in the future (ActiveMQ)

I am working on a system in ActiveMQ where I would prefer not to lose messages. My problem is that repeated messages make my consumers block (instead of working with messages that they can process). I would like to give unsuccessful messages for several days to try again (for example, one of my potential destinations is another server, which I will access through SFTP, which may be unavailable), but I do not want to block users for several days - “I want him to continue working on other posts.”

Is there any way to tell the broker to resend the message later? Right now I'm viewing a message from the queue and putting it on with a delay, but I wonder if there is an easier way. I am using Apache Camel, so a solution using this would be good too.

+7
source share
2 answers

A camel can definitely help with this ...

One way is to use a separate queue and periodically repeat messages separately from the main thread (especially when performance is a problem). In addition, it provides a separate queue so that you can sort these error messages (view, clear, modify, repeat manually, etc.) ...

something like this ... see consumer survey for more details

//main route to process message from a queue (needs to be fast) from("activemq:queue:mainQ").process(...); //handle any errors by simply moving them to an error queue (for retry later) onException(Exception.class) .handled(true).to("activemq:queue:mainErrorQ"); //retry the error queue from("timer://retryTimer?fixedRate=true&period=60000") .bean(myBean, "retryErrors"); ... public void retryErrors() { // loop to empty queue while (true) { // receive the message from the queue, wait at most 3 sec Exchange msg = consumer.receive("activemq:queue.mainErrorQ", 3000); if (msg == null) { // no more messages in queue break; } // send it to the starting queue producer.send("activemq:queue.mainQ", msg); } } 

If you land on a better solution, let me know ... good luck.

+5
source

ActiveMQ trunk now has broker-based delivery support https://issues.apache.org/jira/browse/AMQ-3894

+1
source

All Articles