The action chain

In the course of explaining actions in this chapter, and illustrating actions in many of the quickstarts, we'll mostly concentrate on one action at a time. While this is a useful approach for learning how to use actions, it doesn't make use of the full power of what JBoss ESB can achieve with the "action chain". By chaining actions together, where the message that is the output from one action serves as the input (message) to another action, JBoss ESB enables your services to be constructed of building blocks of loosely coupled, reusable code.

The following code is a sample action chain, defined in the jboss-esb.xml configuration file. This action chain has three actions—a custom action (action1), an OOTB action which prints the message to the console (action2), and an OOTB action which stores the message's contents in a JMX MBean for integration testing (action3).

<actions mep="OneWay">
    <action name="action1"
            class="org.jboss.soa.esb.samples.quickstart.helloworld.MySampleAction"
            process="displayMessage" />
    <action name="action2"
            class="org.jboss.soa.esb.actions.SystemPrintln">
        <property name="printfull" value="false"/>
    </action>
    <!-- The next action is for Continuous Integration testing -->
    <action name="testStore"
            class="org.jboss.soa.esb.actions.TestMessageStore"/>
</actions>

Each action has a name, a class, and an optional process attribute, which specifies the method in the class which will be executed when it receives a message. If no process attribute is specified, it assumes that there is a method within your class

Within the action chain, the service name must be unique—you cannot have two services with the same name or you will receive an error upon deploying your ESB archive.

Notice in the example that there is an mep property on the actions element. MEP stands for Message Exchange Pattern and the supported values of MEP for an action chain are:

  • OneWay: A OneWay MEP means that pipeline will not send a response, that is, at the end of the action chain, it does not send a response.
  • RequestResponse: This MEP means that the pipeline will send a message to the ReplyTo EPR or the From EPR if that isn't specified. We'll talk about what an EPR is in Chapter 7, but for now know that you'll want to use RequestResponse in certain instances, such as when you are using the HttpGateway, or if you are using the ServiceInvoker in synchronous mode.

Let's look at n example:

<actions mep="OneWay">
    <action name="action0"
            class="org.jboss.soa.esb.actions.SystemPrintln">
        <property name="printfull" value="false"/>
    </action>
    <action name="action1" 
            class="org.jboss.soa.esb.samples.quickstart.helloworld.SimpleAdditionAction" 
            process="addMessageContent"/> 
    <action name="action2"
            class="org.jboss.soa.esb.actions.SystemPrintln">
        <property name="printfull" value="false"/>
    </action>
    <action name="action3" 
            class="org.jboss.soa.esb.samples.quickstart.
                   helloworld.SimpleAdditionAction" 
            process="addMessageContent"/>
    <action name="action4"
            class="org.jboss.soa.esb.actions.SystemPrintln">
        <property name="printfull" value="false"/>
    </action>
</actions>

For example, if we send a message containing the number "1" to the chain, the custom action SimpleAdditionAction assumes that the message content is an integer, and adds 1 to it. In this case, we would see output like the following:

15:56:22,407 INFO  [STDOUT] Message structure:
15:56:22,407 INFO  [STDOUT] [1].
15:56:25,408 INFO  [STDOUT] Message structure:
15:56:25,409 INFO  [STDOUT] [2].
15:56:28,409 INFO  [STDOUT] Message structure:
15:56:28,409 INFO  [STDOUT] [3].

The message is printed three times (by action0, action2, and action4). As you notice, you can use the same action class multiple times in the same actionChain in order to repeat functionality. In this case, we print the initial message (1), then add 1 to it, print it (2), add 1 to it again, and then print it a final time (3).

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset