Step 13: Publish and Subscribe to Message Broker Channels

To design the Message Broker functionality described in Understanding the Validation Service Scenario, you create nodes in your RequestQuote business process: one that publishes to the ValidateOrder Message Broker channel and one that subscribes to the StopQuote Message Broker channel. Subsequently, you create a message path on your business process. On the message path, you create the logic to handle the callback from the channel (StopQuote) to which the ValidateOrder service posts a message. That logic specifies that the RequestQuote business process terminates after it receives a callback from the channel to which it is subscribed.

This step includes the following tasks:

To Publish the Request for Quote Message to a Message Broker Channel

You must first create a Message Broker Publish control in your project, then bind a method from the control to a node in your business process. To do so, complete the following steps:

  1. In the Application pane, double-click RequestQuote.jpd to ensure that it is displayed in the Design View.
  2. If the Data Palette is not visible in WebLogic Workshop, click View —> Windows —> Data Palette from the menu bar.
  3. In the Data Palette Controls tab, select Add —> Integration Controls —> MB Publish. The Insert Control dialog box is displayed.
  4. image

  5. In Step 1, enter mbPubValidate as the variable name for this control.
  6. In Step 2, select Create a new MB Publish control to use, then in the New JCX name field, enter MBPubValidate.
  7. In Step 3, click the arrow associated with the channel-name field to display the channels available in your application:
  8. /TutorialPrefix/Tutorial/ValidateOrder 
    
    /TutorialPrefix/Tutorial/StopQuote 
    

    Note: The following channels are also available: /deadletter/xml, /deadletter/string, /deadletter/rawData. To learn about using dead letter channels in your applications, see "Dead Letter Channels" in How Do I: Create Message Broker Channels.

  9. Select /TutorialPrefix/Tutorial/ValidateOrder. This specifies the channel to which your business process publishes the Request for Quote messages it receives from clients.
  10. The message type field is populated with the data type of the message that is published to the ValidateOrder channel: org.example.request.QuoteRequestDocument.

    Note: If the channels are not available for you to select in the channel-name field, you must build your Schemas project. To do so, first click Cancel in the Insert Control dialog box to close it. Then right-click on the Schemas folder in the Application tab and choose Build Schemas from the drop-down menu. When the Schemas project finishes building, click Add —> Integration Controls —> MB Publish on the Data Palette Controls tab to open the Insert Control dialog box. Repeat steps 4 through 6, as described above. The channels are now available in the channel-name field. (The channel files that define Message Broker channels in your application are located in a Schemas project, and must be built in that project for them to be available in your application. To learn how the ValidateOrder channel is defined, see Understanding the Message Broker Channels in Your Tutorial Application.

  11. Click Create. An instance of the MB Publish control in your project is created, the Insert Control dialog box is closed, and the MBPubValidate.jcx file is created and is visible in the Application pane. The instance of the mbPubValidate control you created is displayed in the Data Palette:
  12. image

  13. In the Data Palette, click the following method in the mbPubValidate control:
  14. void publish(QuoteRequestDocument value) 
    
  15. Drag and drop the method onto the RequestQuote business process placing it immediately after the Client Requests Quote Start node.
  16. image

    A Control Send node is created. By default, the node is named publish.

  17. Double-click the publish node. The node builder opens on the General Settings tab. The mbPubValidate control and the void publish (QuoteRequestDocument value) method are already selected.
  18. Click Send Data to open the second tab in the node builder, in which you can specify the message to be published to the ValidateOrder Message Broker channel.
  19. The Control Expects field is populated with the data type of the parameter expected by the control: QuoteRequestDocument.

  20. In the Select variables to assign field, click the arrow to display the variables in your project, then select requestXML (QuoteRequest).
  21. Note: Recall that when you designed the Start node for your business process at the beginning of the tutorial, you assigned the Request for Quote messages from clients to the requestXML variable.

  22. To close the node builder, click X in the top right-hand corner.

To Subscribe to a Message Broker Channel to Receive Messages from a Validation Service

You must create a Message Broker Subscription control in your project, then bind a method from the control to a node in your business process. Using the Message Broker Subscription control, your process subscribes to a channel on which Validation services can publish messages if the Request for Quote from the client is invalid. In the tutorial scenario, a ValidateOrder service determines that a Request for Quote is invalid if the number of widgets requested by a client is greater than 400. Complete the following steps:

  1. Ensure that the RequestQuote business process is displayed in the Design View.
  2. On the Data Palette Controls tab, click Add —> Integration Controls —> MB Subscription. The Insert Control dialog box is displayed.
  3. image

  4. In Step 1, enter mbSubValidate as the variable name for this control.
  5. In Step 2, select Create a new MB Subscription control to use. In the New JCX name field, enter MBSubValidate.
  6. In Step 3, select /TutorialPrefix/Tutorial/StopQuote.
  7. This specifies the channel to which your business process subscribes. It is also the channel to which the ValidateOrder service publishes messages when it determines that a Request for Quote is invalid.

    Note: The message type field is populated with the data type of the message that is published to the StopQuote channel: java.lang.String. To learn how the StopQuote channel is defined, see Understanding the Message Broker Channels in Your Tutorial Application.

  8. Click Create to create an instance of the MB Subscription control in your project.
  9. The Insert Control dialog box is closed and the MBSubValidate.jcx file is created and is visible in the Application pane. The instance of the mbSubValidate control you created is displayed in the Data Palette:

    image

  10. In the Data Palette, click the following method in the mbSubValidate control:
  11. void subscribe() 
    
  12. Drag and drop the method onto the RequestQuote business process in the Design View, placing it immediately after the publish node.
  13. image

    A Control Send node is created. By default, the node is named subscribe. Note that the image indicates that the specifications on this node are complete—no further work is required to design this node.

Note: Message Broker Subscription controls do not define callback methods for you. You must define a custom callback to specify how the business process expects to receive the event messages. To define the callback for your business process, proceed to Step 14: Designing a Message Path for Your Business Process.

This step completes the design of the nodes that specify how your RequestQuote process publishes and subscribes to Message Broker channels.

Related Topics

Understanding the Message Broker Channels in Your Tutorial Application

Message Broker Controls

How Do I: Create Message Broker Channels?

Previous Document Next Document