Retry logic in ActiveMQ and cpp

  activemq, activemq-cpp, c++

I am having a lot of difficulty getting limited retries and dead letter queues to work in ActiveMQ. I am developing using the activemq-cpp library in linux.

This is what I want to do:

  • set DLQ and retry policies on the broker (xml below, schedulerSupport enabled)
  • register a cms::MessageListener against a queue using Auto-acknowledge
  • Have the message get redelivered during segfault according to below policy.

I would really prefer not to have to:

  • use transactional messaging (commit/rollback.. the other ack modes might be acceptable)
  • handle the retry logic at client side (due to segfault possibility)

What I am observing:

  • When the cpp exe crashes with segfault, the message is returned to queue without delay and is never routed to DLQ no matter how many redeliveries. This means the server goes into an infinite crash loop with the poisoned message.
  • If the handleMessage call completes, the message disappears as expected.

Everything I’ve found so far are java examples and seems to imply what I want to do here is impossible. "Dont crash" is not a valid answer for me since this is a large application with a lot of cross development going on so guaranteeing zero segfault in a testing environment is impossible.


                <policyEntry topic=">">
                        <fixedCountSubscriptionRecoveryPolicy maximumSize="100" />
                    <!-- The constantPendingMessageLimitStrategy is used to prevent
                         slow topic consumers to block producers and affect other consumers
                         by limiting the number of messages that are retained
                         For more information, see:

                        <constantPendingMessageLimitStrategy limit="1000" />
                <policyEntry queue=">_REQ">
                          Use the prefix 'DLQ.' for the destination name, and make
                          the DLQ a queue rather than a topic. expire after 7 days 
                          (604,800,000 ms) 
                        <individualDeadLetterStrategy queuePrefix="DLQ." useQueueForQueueMessages="true" expiration="604800000" processNonPersistent="true" />
        <redeliveryPlugin fallbackToDeadLetter="true" 
                        <!-x- a destination specific policy -x->
                        <redeliveryPolicy queue="SpecialQueue" 
                        <!-- the fallback policy for all other destinations -->
                        <redeliveryPolicy maximumRedeliveries="4" 

Source: Windows Questions C++