Skip to Main Content

jms error on receive

bluefrogOct 11 2011 — edited Oct 12 2011
Hi,

This is a duplicate post, that exists on the Oracle AQ forum -
9926612

It is related to JMS however since I am getting a very specific JMS error and thought
I'd post in this forum as I have had no replies in the AQ forum.

The database is 11.2.0.1 on Windows 32bit.The following describes the problem:
----------------------------------
I am attempting a receive a message from a Queue, that has a SYS.AQ$_JMS_TEXT_MESSAGE payload type.
the message was sucessfully placed onto the queue with this JMS session;
9925977

The message exists on the queue;
SQL> col Msg format a20
SQL> select msg_id, msg_state, qt.user_data.text_vc Msg
  2  from aq$jms_qtt_text qt
SQL> / 
 
MSG_ID                           MSG_STATE        MSG
-------------------------------- ---------------- ------------
E9375239910A42518AA0E10DCADC3CB4 READY            Test Message
The queue was created as follows;
exec dbms_aqadm.create_queue_table (queue_table=>'jms_qtt_text', queue_payload_type=>'SYS.AQ$_JMS_TEXT_MESSAGE');
exec dbms_aqadm.create_queue (Queue_name=>'jms_text_que',Queue_table=>'jms_qtt_text');
exec dbms_aqadm.start_queue (queue_name=>'jms_text_que');
I am using the following Java class and Java stored procedure;
SQL> create or replace and compile java source named BasicAQDequeue as
  2  import java.sql.Connection;
  3  import java.sql.Driver;
  4  import java.sql.DriverManager;
  5  import javax.jms.Queue;
  6  import javax.jms.QueueConnection;
  7  import javax.jms.QueueConnectionFactory;
  8  import javax.jms.QueueReceiver;
  9  import javax.jms.QueueSession;
 10  import javax.jms.TextMessage;
 11  import javax.jms.Session;
 12  import oracle.jms.AQjmsFactory;
 13  import oracle.jdbc.*;
 14  import oracle.jdbc.aq.*;
 15  import oracle.jms.*;
 16
 17  public class BasicAQDequeue {
 18
 19      private QueueReceiver     consumer;
 20      private Queue             queue;
 21      private QueueConnection   consumerConnection;
 22      private QueueSession      consumerSession;
 23      private static final String   QUEUE_NAME  = "JMS_TEXT_QUE";
 24      private static final String   QUEUE_OWNER = "XDB_DEV4";
 25      private static final int      ACK_MODE    = QueueSession.AUTO_ACKNOWLEDGE;
 26      private static final boolean  TRANSACTED  = false;
 27
 28      /* Creates and initializes the test. */
 29      public BasicAQDequeue() throws Exception {
 30          super();
 31          // init consumer session - Use Oracle default thin driver connection
 32          Connection conn     = DriverManager.getConnection("jdbc:default:connection:");
 33          consumerConnection  = AQjmsQueueConnectionFactory.createQueueConnection(conn);
 34          consumerSession     = consumerConnection.createQueueSession(TRANSACTED,ACK_MODE);
 35          queue               = consumerSession.createQueue(QUEUE_NAME);
 36          consumer            = consumerSession.createReceiver(queue);
 37      }
 38      public static void main (String args[]) throws Exception
 39        {
 40          BasicAQDequeue qTest  = new BasicAQDequeue();
 41          qTest.run();
 42          qTest.cleanup();
 43        }
 44      /** Closes the JMS connections.throws Exception */
 45      private void cleanup() throws Exception {
 46          // cleanup consumer
 47          System.out.println("Start cleanup.");
 48          consumerConnection.stop();
 49          consumer.close();
 50          consumerSession.close();
 51          consumerConnection.close();
 52          System.out.println("Done.");
 53      }
 54      /* The message send loop. Throws Exception */
 55      private void run() throws Exception {
 56          TextMessage message = (TextMessage) consumer.receive(10);
 57  //        consumerSession.commit(); // This line causes the error
 58          System.out.println("Message received: " + message.getText());
 59      }
 60  }
 61  / 
 
Java created.
 
SQL> create or replace procedure BasicAQDequeue as
  2  language java name 'BasicAQDequeue.main(java.lang.String[])';
  3  / 
 
Procedure created.
 
SQL>
I am getting the following error when I run a test;
SQL> begin
  2    BasicAQDequeue;
  3  end;
  4  / 
Exception in thread "Root Thread" java.lang.NullPointerException
        at BasicAQDequeue.run(BASICAQDEQUEUE:57)
        at BasicAQDequeue.main(BASICAQDEQUEUE:40)
Which suggests that there is no data in the message variable.
So the question in this scenario is why has the "receive" method not worked?

This is my main question, and if I would appreciate getting this answered above my next question.

When I uncomment line 57;
57  //        consumerSession.commit(); // This line causes the error
I get the following error;
SQL> l
  1  begin
  2    BasicAQDequeue;
  3* end;
SQL> / 
Exception in thread "Root Thread" javax.jms.IllegalStateException:
JMS-227: Illegal attempt to commit on a non transacted JMS Session
The question for this scenario is why is the commit not acceptable?
I appreciate there are two questions in this post, but the code is the same.

Any help would be much appreciated.

thanks

Edited by: bluefrog on Oct 11, 2011 11:14 AM
Comments
Post Details
Added on Oct 11 2011
8 comments
420 views