Let us see the real effect of the invmLockStep
attribute on a service. The following steps will demonstrate how to use lock-step delivery:
esbcontent
folder. You will see there is one more file called jboss-esb-lock-step.xml
.<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>
jboss-esb.xml
and click Delete.jboss-esb-lock-step.xml
. Select File | Save As, choose Chapter5/esbcontent/META-INF
and enter the File name as "jboss-esb.xml".src
folder, expand it till the SendLockStepMessage.java
file is displayed in the tree.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; } }
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!].
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.