3 Replies Latest reply: Jan 5, 2013 12:40 PM by damorgan RSS

    AQ + JMS problem

    965923
      Hello everyone!

      I am trying enqueuing and dequeuing messages using Oracle jms api.

      Simple class here:
      package emulator.jms.enqueue.bot;
      
      import java.sql.Connection;
      import java.sql.SQLException;
      import javax.jms.*;
      import oracle.jms.*;
      
      public class QueueConnector
      {
          public QueueConnector(Connection dbConnection)
          {
              connection = dbConnection;
          }
          
          public boolean connect(String queueName, String subscriber) throws SQLException
          {
              try
              {
                  recipientList    = new AQjmsAgent[1];
                  recipientList[0] = new AQjmsAgent(subscriber, "in_queue");
                  
                  queueConnection = AQjmsTopicConnectionFactory.createTopicConnection(connection);
                  queueSession    = queueConnection.createTopicSession(true, TopicSession.CLIENT_ACKNOWLEDGE);
                  queue           = ((AQjmsSession)queueSession).getTopic("konfeta", queueName);
                  
                  queueSender     = ((AQjmsSession)queueSession).createPublisher(queue);
                  
                  topicReceiver = ((AQjmsSession)queueSession).createTopicReceiver(queue, subscriber, null);
              }
              catch(JMSException e)
              {
                  e.printStackTrace();
                  return false;
              }
              
              return true;
          }
          
          public boolean enqueue(String message)
          {
              try
              {
                  TextMessage textMessage = queueSession.createTextMessage(message);
                  ((AQjmsTopicPublisher)queueSender).publish(queue, textMessage, recipientList);
                  queueSession.commit();
              }
              catch(JMSException e)
              {
                  e.printStackTrace();
                  return false;
              }
              
              return true;
          }
          
          public String dequeue()
          {
              try 
              {
                  TextMessage m = (TextMessage)topicReceiver.receive(1000);
                  
                  return m.getText();
              }
              catch(JMSException e) 
              {
                  e.printStackTrace();
                  
                  return null;
              }
          }
          
          private Connection      connection;
          private TopicConnection queueConnection;
          private TopicSession    queueSession;
          private TopicPublisher  queueSender;
          private TopicSubscriber queueReceiver;
          private Topic           queue;
          private TopicReceiver   topicReceiver;
          private AQjmsAgent[]    recipientList;
      }
      This code connect to queue in local database. I am using basin JDBC thin connection.
      Publish message working fine.
      But i can't receive any message from queue. receive() method always return null;

      Next code can receive this messages. It works fine.
      But i need solution with jms :-(
      create or replace procedure test_dequeue(queue_name in varchar2) as
      
         queueopts DBMS_AQ.DEQUEUE_OPTIONS_T;
         msgprops DBMS_AQ.MESSAGE_PROPERTIES_T;
         msgid RAW(16);
         my_msg sys.aq$_jms_text_message;
         
      BEGIN
      
        queueopts.consumer_name := 'moroz';
      
         DBMS_AQ.DEQUEUE (queue_name,
            queueopts,
            msgprops,
            my_msg,
            msgid);
      
         DBMS_OUTPUT.PUT_LINE('OK');
      END;