2
votes

In my development work i have to use Spring batch JmsItemReader to read messages from Hornetq. I am trying the test scenario for rollback the JMS messages to queue in case errors occurs in spring batch process. But it doesnt work for me.

For Ex: Spring step execution table showing Rollback count is 1. But actually i doesnt rollback the message into queue.

I used following configuration in my xml.

<batch:job id="submitOrderJmsToWebServiceJob">
    <batch:step id="submitOrderJmsToLocateStep">
        <batch:tasklet transaction-manager="myTxManager">
            <batch:chunk reader="jmsMessageReader" reader-transactional-queue="true" processor="jmsMessageProcessor"
                writer="jmsMessageToWebSeviceWriter" commit-interval="1" />
        </batch:tasklet>
    </batch:step>       
</batch:job> 
  <bean id="jmsMessageReader" class="org.springframework.batch.item.jms.JmsItemReader">
    <property name="jmsTemplate" ref="orderJmsTemplate" />
</bean>
<bean id="myTxManager" class="org.springframework.jms.connection.JmsTransactionManager">
    <property name="connectionFactory" ref="ConnectionFactory"/>
</bean>
1

1 Answers

1
votes

I solved this issue using following property in spring JMS Template bean.

<property name="sessionTransacted" value="true" /> 

Now jms message could be rollback. Note: I have removed older configuration like transaction-manager attribute in tasklet tag and is transactional queue=true in chunk.