Entering content frame

This graphic is explained in the accompanying text Creating a Message Consumer to a Queue Locate the document in its SAP Library structure

Use

The queue consumer of messages can be QueueReceiver or QueueBrowser.

QueueReceiver enables you to receive and unpack messages, QueueBrowser enables you to browse through the messages only.

Use the QueueBrowser to view messages sent to a Queue without removing them. The QueueBrowser provides a method that enables you to use an instance of java.util.Enumeration class. This enables you to browse through the messages and to scan them, although the messages may expire before the scan end or new messages can be received.

Procedure

If you want to receive messages asynchronously, you must register the class as a javax.jms.MessageListener instance. This enables you to use the onMessage(javax.jms.Message message) method to receive and unpack the messages asynchronously:

This graphic is explained in the accompanying text

public class Example_class implements javax.jms.MessageListener {

    // create subscriber to a queue

    QueueReceiver queueReceiver =  queueSession.createReceiver(queue);

    System.out.println("Receiver created.");

 

    // set message listener

    queueReceiver.setMessageListener(this);

    System.out.println("MessageListener set.");

 

  public void onMessage(javax.jms.Message message) {

    // receive and unpack the message

  }

}

If you want to receive messages synchronously, use the receive() method. Apply it to the message you want to receive.

This graphic is explained in the accompanying text

// create subscriber to a queue

QueueReceiver queueReceiver = queueSession.createReceiver(queue);

System.out.println("Receiver created.");

 

// receive message

TextMessage textMessage = (TextMessage) queueReceiver.receive();

System.out.println("Receiving the message.");

 

Example

For an example, see Queue Sender and Receiver.

 

 

Leaving content frame