This discussion is archived
1 Reply Latest reply: Jul 10, 2013 2:13 AM by pabhat RSS

Dequeue a text message

Filip Huysmans Newbie
Currently Being Moderated
Hello everyone,

DB version :

I'm able to add a text message on an AQ queue, but I'm not able to dequeue it from java.
When I run the dequeue method, it waits ... it doesn't get any message in, even if new messages are being put on the queue.

What am I missing ?

Creation of the AQ queue:
EXEC DBMS_AQADM.STOP_QUEUE('textmessage_queue');
EXEC DBMS_AQADM.DROP_QUEUE('textmessage_queue');
EXEC DBMS_AQADM.DROP_QUEUE_TABLE('queue_textmessage_table');
EXEC DBMS_AQADM.CREATE_QUEUE_TABLE (queue_table => 'queue_textmessage_table', queue_payload_type => 'SYS.AQ$_JMS_TEXT_MESSAGE', multiple_consumers => false);
EXEC DBMS_AQADM.CREATE_QUEUE (queue_name => 'textmessage_queue', queue_table => 'queue_textmessage_table');
EXEC DBMS_AQADM.START_QUEUE (queue_name => 'textmessage_queue');
The createJMSClient(); used by the enqueue and dequeue methods
    private JMSTopic createJMSClient() {
        JMSTopic aq = new JMSTopic();
        try {
            TopicConnectionFactory topicConnectionFactory = null;
            // Get topic connection factory
            Properties info = new Properties();
            info.put(userName, userPassword);
            topicConnectionFactory = AQjmsFactory.getTopicConnectionFactory(connectString, info);
            // Creates an AQ topic connection and session
            aq.connection = topicConnectionFactory.createTopicConnection(userName, userPassword);
            // If a session is transacted, message acknowledgment is handled automatically
            //   by commit and recovery is handled automatically by rollback
            aq.session = aq.connection.createTopicSession(true, // Session is transacted
                        Session.CLIENT_ACKNOWLEDGE); // Acknowledges by commit and rollback
            System.out.println("Successfully created AQ session");
        } catch (Exception ex) {
            System.err.println("AQApplication.createJMS(): " + ex.getMessage());
            System.err.println("user = " + userName + ", password = " + userPassword + ", destination = " +
        return aq;
Java code to enqueue a text message
        JMSTopic client = myMessage.createJMSClient();
        AQjmsSession aqjmssession = (AQjmsSession) client.session;
        AQjmsDestination destination = (AQjmsDestination)aqjmssession.getQueue(myMessage.DB_AQ_ADMIN_NAME, "textmessage_queue");

        TextMessage createTextMessage = aqjmssession.createTextMessage("This is my first text message");
        MessageProducer producer = aqjmssession.createProducer(destination);
Java code to dequeue a text message
        JMSTopic client = myMessage.createJMSClient();
        AQjmsSession aqjmssession = (AQjmsSession)client.session;

        AQjmsDestination destination =
            (AQjmsDestination)aqjmssession.getQueue(myMessage.DB_AQ_ADMIN_NAME, "textmessage_queue");

        MessageConsumer consumer = client.session.createConsumer(destination);

        System.out.println("Waiting for a message ...");
        Message message = consumer.receive();
        System.out.println("Message received !!");


  • Correct Answers - 10 points
  • Helpful Answers - 5 points