简体   繁体   中英

Java messaging service queue session

I am new to JMS. I was trying a sample example where in I send a message to a queue in a session and depending on the flag value session is committed. What i expect from the code is, that when my flag is false, the message remains in the queue and does not get deleted. If flag is true, the session gets committed and i get the message. I am not able to do the former part, ie saving the message in the queue when the flg value is false.

I am using MDPListener and spring framework. Following is my code:

public void onMessage(Message message,Session session) {

        System.out.println("New Message arrived part2 .. Passing to Controller");

        Boolean g=false;

        if(g==true)
        {
            System.out.println("Data true..session committed!!");
            try {
                session.commit();
            } catch (JMSException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        else
        {
            try {
                System.out.println("Sesison not commds!!");

                //HERE I WANT THE CODE TO STORE THE MESSAGE IN THE QUEUE, SO THAT NEXT TIME WHEN THE FLAG IS TRUE, MESSAGE GETS DELIVERED! 
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

Which version of spring are you using.

Anyways check this out:

http://forum.springsource.org/showthread.php?21601-JMS-queue-message-viewing-without-removing-it-from-the-queue

Hope you find it helpful

容器提交会话(除非侦听器抛出异常)。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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