Bugs item #564890, was opened at 2002-06-05 11:13
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=376685&aid=564890&group_id=22866

Category: None
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Josh Cough (joshcough)
Assigned to: Nobody/Anonymous (nobody)
Summary: JMS recover/redelivery errors

Initial Comment:
I am trying to test acknowledgement, non-
acknowledgement, and redelivery in JMS using 
JBoss3.0 Final. 

Unexpected results are occuring, including strange 
behavior and exceptions.

I am sending and receiving from "queue/testQueue", 
which comes default with the JBoss setup.

The code that I am using to attempt this testing can be 
found at http://www.javaworld.com/javaworld/jw-03-
2002/jw-0315-jms_p.html, which page is a document 
describing behavior in certain JMS situations. The code 
can be found below as well. In that page, the author gives
the following statement, which is exactly what I am 
trying to test:

"What happens to messages that are in the session but 
never acknowledged? The messages remain at the 
destination until they expire or forever if they lack an 
expiration date. Message redelivery is not automatic, 
but messages are redelivered under certain 
circumstances. First, calling the Session class's recover
() method recovers the session. Invoking the recover()
method causes the redelivery of all unacknowledged 
messages. Second, the receiving application restarts, 
causing the session to restart. Restarting the session 
causes all unacknowledged messages to be redelivered."


In the first case, "calling the Session class's recover() 
method recovers the session...causes the redelivery of 
all unacknowledged messages", I am getting the 
following error:

javax.jms.IllegalStateException: The session is not 
transacted
        at org.jboss.mq.SpySession.rollback
(SpySession.java:353)
        at org.jboss.mq.SpySession.recover
(SpySession.java:388)
        at Receiver.doAll(Receiver.java:39)
        at ClientReceiver.main(ClientReceiver.java:10)

In the code, i use the statement:  

        aQC.createQueueSession(false, 
Session.CLIENT_ACKNOWLEDGE);

The first argument of "false" declares that the session is 
not in a transaction. Why is rollback being called if I am 
not in a transaction? I expected to re-receive all of my 
unacknowledged messages, but instead got
that exception. Is this a bug in JBoss, or is what I know 
wrong? Any help or advice would be greatly appreciated. 




In the second case, "receiving application restarts, 
causing the session to restart. Restarting the session 
causes all unacknowledged messages to be redelivered" 
I am getting unexpected behavior.

I stop the receiver in two different ways, one by typing 
the "q" button, which tells the code to simply quit and 
exit properly, and the other by issuing a Control-C, 
which of course kills the program. In either case, or
at least in one case, when the receiver starts back up, I 
would expect to get some messages that hadnt yet 
been acknowledged when the receiver went down. I am 
not getting these messages in either case. But...

When I restart JBoss with unacknowledged messages 
in the Queue, then start up the reciever, the messages 
are being delivered. I dont quite understand this 
behavior. Again, is this a bug in JBoss, or is what I know 
wrong? Any help or advice would be greatly appreciated. 



================The Code that I am using 
=====================



import javax.naming.InitialContext;
import javax.jms.*;

public class Sender {
    public static void main(String[] args) {
        System.out.println("Starting...");

        QueueConnectionFactory aQCF = null;
        QueueConnection aQC = null;
        QueueSession aQS = null;
        QueueSender aSender  = null;
        try {
            InitialContext aIC = new InitialContext();
            aQCF = (QueueConnectionFactory) aIC.lookup
("ConnectionFactory");
            aQC = aQCF.createQueueConnection();
            aQS = aQC.createQueueSession(false, 
Session.AUTO_ACKNOWLEDGE);
            Queue aQueue = (Queue) aIC.lookup
("queue/testQueue");
            aSender = aQS.createSender(aQueue);
            aQC.start();
            for (int i = 0; i < 10; i++) {
                aSender.send(aQS.createObjectMessage
(new Integer(i)));
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                if (aSender != null) {
                    aSender.close();
                }
                if (aQS != null) {
                    aQS.close();
                }
                if (aQC != null) {
                    aQC.stop();
                    aQC.close();
                }
            } catch (JMSException e) {
                e.printStackTrace();
            }
        }

        System.out.println("Ending...");
    }
}






import javax.jms.*;
import javax.naming.InitialContext;
import java.io.InputStreamReader;

public abstract class Receiver {
    protected void doAll() {
        QueueConnectionFactory aQCF = null;
        QueueConnection aQC = null;
        QueueSession aQS = null;
        QueueReceiver aQR  = null;
        try {
            InitialContext aIC = new InitialContext();
            aQCF = (QueueConnectionFactory) aIC.lookup
("ConnectionFactory");
            aQC = aQCF.createQueueConnection();
            aQS = createQueueSession(aQC);
            final QueueSession aQS1 = aQS;
            Queue aQueue = (Queue) aIC.lookup
("queue/testQueue");
            aQR = aQS.createReceiver(aQueue);
            MessageListener aML = new MessageListener() 
{
                public void onMessage(Message aMessage) {
                    try {
                        processMessage(aMessage, aQS1);
                    } catch (JMSException e) {
                        e.printStackTrace();
                    }
                }
            };
            System.out.println( "Setting message listener" );
            aQR.setMessageListener(aML);
            System.out.println( "Starting..." );
            aQC.start();
            InputStreamReader aISR = new 
InputStreamReader(System.in);
            char aAnswer = ' ';
            do {
              System.out.println( "Reading" );
                aAnswer = (char) aISR.read();
                if ((aAnswer == 'r') || (aAnswer == 'R')) {
                    aQS.recover();
                }
            } while ((aAnswer != 'q') && (aAnswer != 'Q'));
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                if (aQR != null) {
                    aQR.close();
                }
                if (aQS != null) {
                    aQS.close();
                }
                if (aQC != null) {
                    aQC.stop();
                    aQC.close();
                }
            } catch (JMSException e) {
                e.printStackTrace();
            }
        }
    }


----------------------------------------------------------------------

You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=376685&aid=564890&group_id=22866

_______________________________________________________________

Don't miss the 2002 Sprint PCS Application Developer's Conference
August 25-28 in Las Vegas -- http://devcon.sprintpcs.com/adp/index.cfm

_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to