Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/377.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java JMS队列:如何在队列中存储消息,直到标志设置为true_Java_Jms_Spring Jms - Fatal编程技术网

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

Java JMS队列:如何在队列中存储消息,直到标志设置为true,java,jms,spring-jms,Java,Jms,Spring Jms,我正在尝试JMS队列的一个示例应用程序。。我希望队列中的消息保持在那里,直到我的标志设置为true。我正在使用spring框架和具有以下配置的MDP侦听器: Server-context.xml: <bean id="MDPListener" class="controller.MDPListener"></bean> <bean id="connectionFactory" class="org.apache.activemq.ActiveMQConnectio

我正在尝试JMS队列的一个示例应用程序。。我希望队列中的消息保持在那里,直到我的标志设置为true。我正在使用spring框架和具有以下配置的MDP侦听器:

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>

现在,当抛出异常时,消息将留在队列中,控件将返回到同一个侦听器,该侦听器将再次侦听同一消息,并在一段时间后停止。这会导致死队列。我无法存储该消息。我希望我的侦听器侦听队列,而不是上一条消息,而是下一条消息。请帮忙

JMS不是这样工作的-您必须将消息移动到代码中的另一个队列


或者,使用ActiveMQ,您可以配置重新传递策略以更快地将消息发送到DLQ(我认为默认值为6次重试)。

我认为JMS队列是存储东西的非常糟糕的地方。如果你不想你的信息被传递出去,就不要把它放到队列里。感谢上帝!最后是一个简单而中肯的答案!脱帽致敬D现在为我工作。。归还政策是关键
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");
        }
}