简体   繁体   English

JMS QUEUE:如何将消息存储在队列中,直到标志设置为true

[英]JMS QUEUE: how to store message in the queue until flag is set to true

I was trying a sample application of JMS queue.. I want the message coming in the queue to stay there until my flag is set to true. 我正在尝试JMS队列的示例应用程序。我希望进入队列的消息保持在那里,直到我的标志设置为true。 I am using spring framework and an MDP Listener with following configuration: 我正在使用具有以下配置的spring框架和MDP侦听器:

Server-context.xml: Server-context.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>

My onMessage has the following code: 我的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");
        }
}

Now when an exception is thrown, the message stays back in the queue and the control goes back to the same listener which listens to the same message all over again and stops after sometime. 现在,当引发异常时,消息将保留在队列中,并且控件将返回到同一侦听器,该侦听器将再次侦听同一消息并在一段时间后停止。 This results in dead queue. 这导致死队列。 I am unable to store that message. 我无法存储该消息。 I want my listener to listen to the queue but not to the previous message but next one. 我希望我的听众听队列,但不听上一条消息,而是听下一条。 Please help! 请帮忙!

JMS doesn't work that way - you have to move the message to another queue in your code. JMS不能那样工作-您必须将消息移到代码中的另一个队列中。

Or, with ActiveMQ, you can configure the redelivery policy to send the message to the DLQ faster (I believe the default is 6 retries). 或者,使用ActiveMQ,您可以配置重新交付策略以更快地将消息发送到DLQ(我相信默认值为6次重试)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM