具有客户端确认的默认消息侦听器会导致即使未确认也会从队列中删除消息

时间:2014-09-02 07:02:48

标签: java jms jboss6.x spring-jms jca

我正在使用Default消息侦听器类来侦听使用资源适配器在Jboss中配置的MQ。会话确认模式设置为客户端确认。如果处理成功,我会收到消息。

但是如果发生故障,我不会确认该消息,但仍会从队列中删除。我正在使用session.recover设置重新传递。这可能有什么不对。为什么不起作用?理想情况下,消息应该保持排队直到它得到确认。使用的Jboss版本是6.0

这是代码

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>

0 个答案:

没有答案