Message Broker Subscription Control

Two Message Broker controls are available from your business processes: Publish and Subscription. Your business process uses a Subscription control to dynamically subscribe to channels and receive messages. You bind the channel and optionally, an XQuery expression for filtering messages, when you create an instance of the control for your business process. The bindings cannot be overridden dynamically.

The Subscription control interface includes methods that allow your business process to subscribe to and unsubscribe from the bound Message Broker channel.

Subscribe operations are part of the larger XA transaction, as with other business process operations. This allows subscribe operations to be rolled back if the business process operation fails. Because a subscription is in a transaction, you have to commit the transaction to make it durable. If you're doing non-transactional work, that is, if a subscribe operation must be committed before performing an action that might trigger a return message, use <transaction/> blocks in the flow to commit the current business process state, including the subscription.

For information on how to add control instances to business processes, see Using Controls in Business Processes.

The following topics provide information about creating and using Message Broker Subscription controls:

To Create an Instance of a Message Broker Subscription Control

  1. Click Add on the Controls tab to display a list of controls that represent the resources with which your business process can interact.
  2. Note: If the Controls tab is not visible in WebLogic Workshop, click View —> Windows —> Data Palette from the menu bar.

  3. Choose Integration Controls to display the list of controls used for integrating applications.
  4. Choose MB Subscription. The Insert Control dialog box is displayed.
  5. In the Insert Control dialog box (Step 1), enter a name for the instance of this control. The name you enter must be a valid Java identifier.
  6. In the Insert Control dialog box (Step 2), select one of the following options:
  7. In the Insert Control dialog box (Step 3), specify the channel name as follows:
  8. Select the This subscription will be filtered check box if you want to subscribe using filter values.
  9. Click Create to close the Insert Control dialog box.
  10. An instance of a MB Subscription control is created in your project and displayed in the Controls tab. The following figure shows an example instance of a MB Subscription control displayed in the Controls tab:

    image

    The control declaration is written to your JPD source file.

/**
  * @common:control
  */
  private processes.mbSubscribe mbSubscribe; 

JCX File for Your MB Subscription Control

When you create a new MB Subscription control, you create a new JCX file in your project. The following example JCX file is automatically created by the control wizard:

import com.bea.control.SubscriptionControl;  
import com.bea.data.RawData; 
import com.bea.xml.XmlObject;  
/** 
 * Defines a new Subscription control. 
 * 
 * @jc:mb-subscription-control channel-name="/controls/channel1" 
 */  
public interface mbSubscribe extends SubscriptionControl,
 com.bea.control.ControlExtension
{ 
    /** 
     * @jc:mb-subscription-method filter-value-match="{value}" 
     */  
    void subscribeWithFilterValue(String value);  
    interface Callback extends SubscriptionControl.Callback { 
        /** 
         * @jc:mb-subscription-callback message-body="{message}" 
         */  
       void onMessage(XmlObject message); 
    } 
}   

You must select the This subscription will be filtered check box to ensure that the subscribeWithFilterValue() method in included in the JCX file. The onMethod method on the Calback interface uses the message type defined in the channel file.

Using Methods of the MB Subscription Interface

This section describes the MB Subscription control interface.The methods you can use to subscribe to Message Broker channels are available from within your application.

Class Interface

package com.bea.control; 
import weblogic.jws.control.Control; 
/**
 * Message Broker Subscription control base interface 
 */ 
public interface SubscriptionControl extends Control
{ 
/**
     * Subscribes the control to the message broker. If the subscription
     * uses a filter expression, then the default filter value will be
     * used. If no default filter value is defined in the annotations,
     * then a <tt>null</tt> filter value will be used, meaning that any
     * filter result will trigger a callback.
     */ 
    void subscribe(); 
    /**
     * Unsubscribes the control from the message broker, stopping
     * further events (messages) from being delivered to the control.
     */ 
    void unsubscribe();
    
    interface Callback {
        /** 
         * Internal callback method used to implement user-defined callbacks.
         * JPDs cannot and should not attempt to implement this callback method.
         *
         * @param msg  the message that triggered the subscription
         * @throws Exception
         *
        void _internalCallback(Object msg) throws Exception;
         */
    }
} 

Note: If the subscription uses a filter, you must define custom subscription methods to specify the filter value to be matched at run time.

The Subscription control does not define callback methods for you. You must define a custom callback to specify how the business process expects to receive the event messages. (Event messages can be XML, raw data, or string.)

To learn more about the methods available on the MB Subscription control, see the SubscriptionControl Interface Javadoc.

Method Attributes

This section describes the class and method attributes supported for the Subscription control.

Class attributes include:

Method attributes include:

Callback method attributes include:

Example Code for MB Subscription Control

MB Subscription controls must be extended. The following is an example of how to code a MB Subscription control in your JPD file.

/*
 * @jc:mb-subscription-control 
 *         channel-name="/controls/stocks" 
 *         xquery="$message/StockSymbol/text()"
 */
interface MySubscriptionControl extends SubscriptionControl, ControlExtension {
    /**
     * @jc:mb-subscription-method
     *      filter-value-match="BEA"
     */
    void subscribeToBEA();
    /**
     * @jc:mb-subscription-method
     *      filter-value-match="{symbol}"
     */
    void subscribeToSymbol(String symbol);
    interface Callback {
        /**
         * @jc:mb-subscription-callback message-body="{myMsgReceived}"
         */
        onXMLMessage(XmlObject myMsgReceived);
   }
}
.
.
.
/*
 * @common:control
 */
 MySubscriptionControl subCtrl;
// subscribe to a message 
void subscribeIt() {
      subCtrl.subscribeToBEA();
}
// receive a message after subscribing
subCtrl_onXMLMessage(XmlObject myMsgReceived)
{
} 

Note About Static and Dynamic Subscriptions to Message Broker Channels

In addition to the dynamic subscriptions you design at Control nodes in your business process, you can design static subscriptions at Start nodes to receive messages from Message Broker channels.

To learn how to design static subscriptions to Message Broker channels at business process Start nodes, see Designing Start Nodes.

Previous Document Next Document