I am using Default message listener class for listening to MQ which is configured in Jboss using resource adapter. The session acknowledge mode is set to Client acknowledge . I am acknowledging the message if the processing is successful .
However in case of failure I am not acknowledging the message but still it gets deleted from queue. I am setting up re-delivery using session.recover. What could be wrong here. Why is it not working? Ideally the message should hold on to queue till it gets acknowledged. Jboss version used is 6.0
Here is the code
public class EventListener implements SessionAwareMessageListener {
@Override
public void onMessage(Message message, Session session) {
Event event = null;
try {
message.acknowledge();
} catch (ValidationException validationException) {
try {
message.acknowledge();
} catch (JMSException e) {
}
} catch (RouterException routerException) {
session.recover();
} catch (NoMatchingRouterException noMatchingRouterException) {
try {
message.acknowledge();
} catch (JMSException e) {
} catch (Exception e) {
}
} catch (Exception e) {
}
}
}
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee"
xsi:schemaLocation="http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<jee:jndi-lookup id="eventQueueConnectionFactory" jndi-name="java:/eventQueueConnectionFactory" proxy-interface="javax.jms.QueueConnectionFactory"/>
<jee:jndi-lookup id="eventQueueDestination" jndi-name="java:/EventMQ"/>
<bean id="eventQueueMessageListener" class="com.eventtier.listener.EventListener" />
<bean id="dmsEventJmsContainer" class="org.springframework.jms.listener.DefaultMessageListenerContainer">
<property name="connectionFactory" ref="eventQueueConnectionFactory"/>
<property name="destination" ref="eventQueueDestination"/>
<property name="messageListener" ref="eventQueueMessageListener" />
<property name="sessionAcknowledgeMode" value="2"/>
<property name="sessionTransacted" value="false" />
<property name="concurrentConsumers" value="10"/>
<property name="maxConcurrentConsumers" value="20"/>
</bean>
</beans>