Messaging Scenarios Supported by the JMS Control

This topic describes specific messaging scenarios that are supported by the JMS control.

To learn more about WebLogic Workshop controls, see Controls: Using Resources from a Web Service.

To learn more about JMS, the Java Message Service, see Overview: Messaging Systems and JMS.

To learn more about the JMS control, see JMS Control: Using Java Message Service Queues and Topics from Your Web Service.

Supported Messaging Scenarios

The JMS specification supports a wide variety of messaging scenarios. Some scenarios that are possible in standalone applications are not possible in the WebLogic Workshop environment due to the nature of web services.

The messaging scenarios in the following sections are supported by the JMS control. For descriptions of messaging scenarios that are not supported by the JMS control, see Messaging Scenarios Not Supported by the JMS Control.

Send Messages to a Queue

A web service, via a JMS control, may send messages to a JMS queue. The web service will not receive a reply. The queue must exist and be registered in the JNDI registry. The administrator who configures the target JMS queue determines the delivery guarantee policies.

Example

To implement this scenario:

  1. On the JMS control, specify the name of the target JMS queue as the value of the send-jndi-name attribute of the JMS control's @jws:jms property. To learn how to create a JMS control, see Creating a New JMS Control.

  2. From your web service, call the JMS control's default method (sendTextMessage, sendMessage, sendObjectMessage or sendJMSMessage depending on the message type selected when the control was created); or a custom method you have defined for the JMS control.

The following is an example of this scenario. The example assumes you have followed the steps above.

public class MyService {
 
    /** 
     *   @jws:control
     */
    private MyQueueControl myQueue;
 
 
    /**
     * @jws:operation
     */
    public void sendID(String personID)
    {
        myQueue.sendTextMessage( personID );
    }
}

Two-Way Messaging with Queues

A web service, via a JMS control, may send messages to one queue and receive reply messages on another queue. A single JMS control may have both send and receive queues configured, and web services may then send and receive via the same control.

Note: Two-way messaging requires correlation of every received messages with the instance of the web service that sent the original outgoing message. This is typically managed for you by the JMS control with no action necessary on your part. To learn more about message correlation, see the explanation of the send-correlation-property and receive-correlation-property attributes in @jws:jms Tag.

Example

To implement this scenario:

  1. On the JMS control, specify the name of the JMS queue to which you want to send messages as the value of the send-jndi-name attribute of the JMS control's @jws:jms tag.

  2. Specify the name of the JMS queue from which you want to receive messages as the value of the receive-jndi-name attribute of the JMS control's @jws:jms tag.

  3. To send a message from your web service, call the JMS control's default method (sendTextMessage, sendMessage, sendObjectMessage or sendJMSMessage depending on the message type selected when the control was created); or a custom method you have defined for the JMS control.

  4. To be notified when messages are received on the receive queue, implement a callback handler for the JMS control’s callback (receiveTextMessage, receiveMessage, receiveObjectMessage or receiveJMSMessage depending on the message type selected when the control was created); or a custom callback you have defined for the JMS control.

The following is an example of this scenario:

public class MyService {
 
    /** 
     *   @jws:control
     */
    private MyQueueControl myQueue;
 
    /**
     * @jws:operation
     */
    public void sendID(String personID) throws Exception
    {
        myQueue.sendTextMessage( personID );
    }


 
   myQueue_receiveTextMessage(String message)    {        // message has arrived from queue, perform desired operations    }   }

Publish to a Topic

A web service, via a JMS control, may publish messages to a JMS topic. The web service will not receive a reply. The topic must exist and be registered in the JNDI registry.

Example

To implement this scenario:

  1. On the JMS control, specify the name of the target JMS topic as the value of the send-jndi-name attribute of the JMS control's @jws:jms property.

  2. From your web service, call the JMS control's default method (sendTextMessage, sendMessage, sendObjectMessage or sendJMSMessage depending on the message type selected when the control was created); or a custom method you have defined for the JMS control.

The following is an example of this scenario:

public class MyService {
 
    /** 
     *   @jws:control
     */
    private MyTopicControl myTopic;
 
    /**
     * @jws:operation
     */
    public void sendID(String personID) throws Exception
    {
        myTopic.sendTextMessage( personID );
    }
}

Subscribe to a Topic

A web service, via a JMS control, may subscribe to messages on a JMS topic. The topic must exist and be registered in the JNDI registry. Only messages sent after the web service has subscribed to the topic will be received.

Example

To implement this scenario:

  1. On the JMS control, specify the name of the target JMS topic as the value of the receive-jndi-name attribute of the JMS control's @jws:jms tag.

  2. From your web service, call the JMS control's subscribe method .

  3. To be notified when messages are received on the receive topic, implement a callback handler for the JMS control’s callback (receiveTextMessage, receiveMessage, receiveObjectMessage or receiveJMSMessage depending on the message type selected when the control was created); or a custom callback you have defined for the JMS control.

  4. To stop being notified when messages are received on the receive topic, call the JMS control's unsubscribe method.

The following is an example of this scenario:

public class TopicForwardingService {


   /**     * @jws:control
    */    private MyTopicControl myTopic;
   /**     * @jws:operation     * @jws:conversation phase=start     */    public void registerListener()    {        myTopic.subscribe();    }
   /**     * @jws:operation     * @jws:conversation phase="finish"     */    public void unregisterListener()    {        // This isn't strictly necessary, the JWS will always        // be unsubscribed on conversation finish.        myTopic.unsubscribe();    }
   myTopic_receiveTextMessage(String message)    {        // message has arrived from queue, perform desired operations    }   }

Related Topics

Overview: Messaging Systems and JMS

Messaging Scenarios Not Supported by the JMS Control

@jws:jms Tag

@jws:jms-header Tag

@jws:jms-message Tag

@jws:jms-property Tag