我正在尝试 JMS 队列的示例应用程序。我希望队列中的消息保持在那里,直到我的标志设置为 true。我正在使用 Spring 框架和具有以下配置的 MDP 侦听器:
服务器上下文.xml:
<bean id="MDPListener" class="controller.MDPListener"></bean>
<bean id="connectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL">
<value>tcp://localhost:61616</value>
</property>
</bean>
<bean id="dataQueue" class="org.apache.activemq.command.ActiveMQQueue">
<constructor-arg value="dataQueue15"></constructor-arg>
</bean>
<bean id="container" class="org.springframework.jms.listener.DefaultMessageListenerContainer">
<property name="connectionFactory" ref="connectionFactory"/>
<property name="messageListener" ref="MDPListener"/>
<property name="destination" ref="dataQueue"/>
<property name="sessionTransacted" value="true"/>
</bean>
我的 onMessage 有以下代码:
public void onMessage(Message message,Session session) {
System.out.println("The session: "+session.toString());
System.out.println("New Message arrived part2 .. Passing to Controller");
Boolean g=false;
if(g==true)
{
System.out.println("Data true..session committed!!");
}
else
{
System.out.println("in the queue");
throw new RuntimeException("Saved");
}
}
现在,当抛出异常时,消息会保留在队列中,并且控件会返回到同一个侦听器,该侦听器会重新侦听相同的消息并在一段时间后停止。这会导致死队列。我无法存储该消息。我希望我的听众收听队列,但不是上一条消息,而是下一条消息。请帮忙!