How is ordering preserved in ActiveMQ?

2019-09-09 04:38发布

问题:

I have set up an application to listen to an ActiveMQ topic. Here's the way I have configured it:

<jms:listener-container connection-factory="jmsFactory"
    container-type="default" destination-type="durableTopic" client-id="CMY-LISTENER"
    acknowledge="transacted">
    <jms:listener destination="CMY.UPDATES"
        ref="continuingStudiesCourseUpdateListener" subscription="CMY-LISTENER" />
</jms:listener-container>


<bean id="jmsFactoryDelegate" class="org.apache.activemq.ActiveMQConnectionFactory">
    <property name="brokerURL" value="${jmsFactory.brokerURL}" />
    <property name="redeliveryPolicy">
        <bean class="org.apache.activemq.RedeliveryPolicy">
            <property name="maximumRedeliveries" value="10" />
            <property name="initialRedeliveryDelay" value="60000" />
            <property name="redeliveryDelay" value="60000" />
            <property name="useExponentialBackOff" value="true" />
            <property name="backOffMultiplier" value="2" />
        </bean>
    </property>
</bean>

The problem I have is this:

I put 10 messages into the topic.

If the first message is read, and the application fails to process the task, it rolls back the message.

1 minute later, it retries to read the first message and process it. It fails and rolls back.

2 minutes later, it retries, and rolls back.

4 minutes later... etc

It gets stuck on the first message and the next 9 messages don't get read until the first one is dealt with.

Is this the way a topic is supposed to work? Is there a way that I can have my 9 other messages read while the first one is waiting to be re-tried?

回答1:

Its working just like its supposed to, that's the nature of transactional message processing. You can't process the other messages until the first one completes or is discarded based on the rules in your given redelivery policy.

Might want to read though the JMS tutorial here: