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.

Thanks

  <destinationPolicy>
        <policyMap>
            <policyEntries>
                <policyEntry topic=">">
                    <subscriptionRecoveryPolicy>
                        <fixedCountSubscriptionRecoveryPolicy maximumSize="100" />
                    </subscriptionRecoveryPolicy>
                    <!-- 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:

                         http://activemq.apache.org/slow-consumer-handling.html
                        -->
                    <pendingMessageLimitStrategy>
                        <constantPendingMessageLimitStrategy limit="1000" />
                    </pendingMessageLimitStrategy>
                </policyEntry>
                <policyEntry queue=">_REQ">
                    <deadLetterStrategy>
                        <!--
                          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" />
                    </deadLetterStrategy>
                </policyEntry>
            </policyEntries>
        </policyMap>
    </destinationPolicy>
    <plugins>
        <redeliveryPlugin fallbackToDeadLetter="true" 
                          sendToDlqIfMaxRetriesExceeded="true">
            <redeliveryPolicyMap>
                <redeliveryPolicyMap>
                    <!--
                    <redeliveryPolicyEntries>
                        <!-x- a destination specific policy -x->
                        <redeliveryPolicy queue="SpecialQueue" 
                                          maximumRedeliveries="4" 
                                          redeliveryDelay="10000"/>
                    </redeliveryPolicyEntries>
                    -->
                    <defaultEntry>
                        <!-- the fallback policy for all other destinations -->
                        <redeliveryPolicy maximumRedeliveries="4" 
                                          initialRedeliveryDelay="1000"
                                          redeliveryDelay="5000"/>
                    </defaultEntry>
                </redeliveryPolicyMap>
            </redeliveryPolicyMap>
        </redeliveryPlugin>
    </plugins>

Source: Windows Questions C++

LEAVE A COMMENT