Bertrand
Bertrand

Reputation: 109

JMS Transaction simple example

I try to implement a simple jms transaction test. I want to check that my message is left in my ActiveMQ broker's queue after an exception occurs in my route.

In this test, the exception occurs after a new message is posted in the queue but the message is not in the queue any longer as I was expecting. What I'am missing ? blueprint code below

<bean id="jmstx" class="org.apache.camel.component.jms.JmsComponent">
    <property name="configuration" ref="jmsConfig" />
</bean>

<bean id="jmsConfig" class="org.apache.camel.component.jms.JmsConfiguration">
    <property name="connectionFactory" ref="jmsConnectionFactory" />
    <property name="transactionManager" ref="jmsTransactionManager" />
    <property name="transacted" value="true" />
    <property name="cacheLevelName" value="CACHE_CONNECTION" />
</bean>

<bean id="jmsTransactionManager"
    class="org.springframework.jms.connection.JmsTransactionManager">
    <property name="connectionFactory" ref="jmsConnectionFactory" />
</bean>

<bean id="jmsConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
    <property name="brokerURL" value="tcp://localhost:61616" />
    <property name="userName" value="smix" />
    <property name="password" value="smix" />
    <property name="redeliveryPolicy">
        <bean class="org.apache.activemq.RedeliveryPolicy">
            <property name="maximumRedeliveries" value="0" />
        </bean>
    </property>
</bean>

<bean id="myEx" class="java.lang.Exception" />

<camelContext id="ctx_m27" xmlns="http://camel.apache.org/schema/blueprint">
    <route id="rt_m27_01" trace="false" autoStartup="true">
        <from uri="jmstx:queue:Q.m27_IN" />
        <throwException ref="myEx" />
        <to uri="jmstx:queue:Q.m27_OUT" />
    </route>
</camelContext>

Upvotes: 2

Views: 3438

Answers (2)

Bertrand
Bertrand

Reputation: 109

Thanks to Claus answer, I've changed redeliveryPolicy to :

    <property name="redeliveryPolicy">
        <bean class="org.apache.activemq.RedeliveryPolicy">
            <property name="maximumRedeliveries" value="-1" />
            <property name="initialRedeliveryDelay" value="2000" />
            <property name="redeliveryDelay" value="60000" />
            <property name="useExponentialBackOff" value="false"/>
        </bean>
    </property>

In fact, cacheLevelName parameter need also to be changed to :

<property name="cacheLevelName" value="CACHE_CONSUMER" />

Default value (CACHE_AUTO), CACHE_NONE and CACHE_SESSION causes strangely redelivery delay to 0.

Upvotes: 2

Claus Ibsen
Claus Ibsen

Reputation: 55540

You have configured the broker to not use redelivery, eg

<property name="maximumRedeliveries" value="0" />

So when the transaction fails, the message is not redelivered, and then the broker moves the message to its dead letter queue (DLQ). So the message is there.

You can read more about the DLQ in ActiveMQ here: http://activemq.apache.org/message-redelivery-and-dlq-handling.html

Upvotes: 3

Related Questions