Time for action – using lock-step delivery

Let us see the real effect of the invmLockStep attribute on a service. The following steps will demonstrate how to use lock-step delivery:

  1. In JBoss Developer Studio, select Chapter5 and expand the esbcontent folder. You will see there is one more file called jboss-esb-lock-step.xml.
  2. Have a look at this file. The relevant section for lock-step delivery has been highlighte here:
    <service category="Chapter5Sample"
             description="Chapter5 B Service"
             invmScope="GLOBAL" name="Chapter5BService">
      <property name="inVMLockStep" value="true"/>
      <property name="inVMLockStepTimeout" value="4000"/>
      <actions mep="OneWay">
        <action class="org.jboss.soa.esb.samples.chapter5.MyAction"
                name="lockStepAction" process="lockStepAction"/>
        <action class="org.jboss.soa.esb.actions.SystemPrintln"
                name="printMessage">
          <property name="message" value="Incoming to B"/>
        </action>
      </actions>
    </service>
  3. Before we rename the file, we need to remove the deployed application from the server. Click on the Servers tab and right click on the Chapter5 application and click Remove.
  4. Now right click on the file jboss-esb.xml and click Delete.
  5. Click OK on the Confirm Delete dialog.
  6. Open jboss-esb-lock-step.xml. Select File | Save As, choose Chapter5/esbcontent/META-INF and enter the File name as "jboss-esb.xml".
  7. Click OK.
  8. Select the Chapter5 project and click Run | Run As | Run on Server.
  9. Select the src folder, expand it till the SendLockStepMessage.java file is displayed in the tree.
  10. Examine the SendLockStepMessage.java file. You can see that it invokes the Chapter5Service ten times:
    public static void main(String[] args) throws Exception {
        System.setProperty("javax.xml.registry.ConnectionFactoryClass","org.apache.ws.scout.registry.ConnectionFactoryImpl");
        Message esbMessage = MessageFactory.getInstance().getMessage();
        esbMessage.getBody().add("Chapter 5 says Hello!");
        ServiceInvoker invoker = new ServiceInvoker("Chapter5Sample", "Chapter5Service");
        for (int i = 0; i < 10; i++) {
            invoker.deliverAsync(esbMessage);
        }
    }

    Here is the listing of MyAction.java that highlights the code where the message processing is elayed:

    public class MyAction extends AbstractActionLifecycle {
    
        protected ConfigTree  _config;
    
        public MyAction(ConfigTree config) {
            _config = config;
        } 
    
        public Message process(Message message) throws Exception {
            System.out.println("Body: " + message.getBody().get());
            return message;
        }
    
        public Message lockStepAction(Message message)throws Exception {
            Thread.sleep(2000);
            return message;
        }
    
        public Message printMessage(Message message)throws Exception {
            System.out.println("Routing to B");
            return message;
        }
    }
  11. With the SendLockStepMessage.java file selected, click Run | Run As | Java Application.

    The following is a sample output from the server console:

    15:15:20,078 INFO  [STDOUT] Routing to B
    15:15:20,093 INFO  [STDOUT] Routing to B
    15:15:22,093 INFO  [STDOUT] Incoming to B:
    15:15:22,093 INFO  [STDOUT] [Chapter 5 says Hello!].
    15:15:22,093 INFO  [STDOUT] Routing to B
    15:15:24,093 INFO  [STDOUT] Incoming to B:
    15:15:24,093 INFO  [STDOUT] [Chapter 5 says Hello!].
    15:15:24,093 INFO  [STDOUT] Routing to B
    15:15:26,093 INFO  [STDOUT] Incoming to B:
    15:15:26,093 INFO  [STDOUT] [Chapter 5 says Hello!].
    15:15:26,093 INFO  [STDOUT] Routing to B
    15:15:28,093 INFO  [STDOUT] Incoming to B:
    15:15:28,093 INFO  [STDOUT] [Chapter 5 says Hello!].
    15:15:28,109 INFO  [STDOUT] Routing to B
    15:15:30,093 INFO  [STDOUT] Incoming to B:
    15:15:30,093 INFO  [STDOUT] [Chapter 5 says Hello!].
    15:15:30,109 INFO  [STDOUT] Routing to B
    15:15:32,093 INFO  [STDOUT] Incoming to B:
    15:15:32,093 INFO  [STDOUT] [Chapter 5 says Hello!].
    15:15:32,109 INFO  [STDOUT] Routing to B
    15:15:34,109 INFO  [STDOUT] Incoming to B:
    15:15:34,109 INFO  [STDOUT] [Chapter 5 says Hello!].
    15:15:34,109 INFO  [STDOUT] Routing to B
    15:15:36,109 INFO  [STDOUT] Incoming to B:
    15:15:36,109 INFO  [STDOUT] [Chapter 5 says Hello!].
    15:15:36,109 INFO  [STDOUT] Routing to B
    15:15:38,109 INFO  [STDOUT] Incoming to B:
    15:15:38,109 INFO  [STDOUT] [Chapter 5 says Hello!].
    15:15:40,109 INFO  [STDOUT] Incoming to B:
    15:15:40,109 INFO  [STDOUT] [Chapter 5 says Hello!].
    

What just happened?

You executed an application that uses the InVM lock-step delivery mechanism in its configuration. Notice that the Routing to B message is displayed almost every two seconds, the time our MyAction lockStepAction method sleeps. The delivery of the message from Chapter5Service to Chapter5Bservice has been blocked until ChapterBService is able to retrieve it.

InVM threads

In the previous section you noticed that the message was printed after every two seconds. That is because the number of InVM threads that were available for processing was just one. The number of listener threads associated with the InVM transport can be controlled by the maxThreads property.

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

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