Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

...

This document describes how to run ServiceMix's BPEL example and provides details about what it does. For information on the business use case, please refer to: Use Case for BPEL.

The BPEL example illustrates the following:

  • an example of declarative programming
  • how to interact with the file systemperform BPEL integration with ServiceMix
  • how to use a WorkManager thread pool JmsTemplate for publishing and subscribing to ActiveMQ topics

The XML code for the BPEL example is located in the ServiceMix installation directory under the examples\file-bindingbpel directory in the servicemix.xml file. It is recommended that you refer to the servicemix.xml file while reading this document.

The BPEL XML file, servicemix.xml, contains two components and a supporting bean. One component waits for a file to be deposited into the the inbox directory, retrieves it, creates a normalized message that contains the file, then sends the message to the Normalized Message Router (NMR). The NMR routes the file to another component, which deposits it into an outbox directory.

Running the BPEL Example

From a command shell, go to the BPEL example directory:

Code Block

cd [servicemix_install_dir]\examples\file-binding

where servicemix_install_dir is the directory in which ServiceMix was installed.

Then type:

Code Block

[servicemix_install_dir]\bin\servicemix servicemix.xml

OR

..\..\bin\servicemix servicemix.xml

...

This example has a client application, JMSClient, which sends a SOAP message to a ServiceMix binding component called myComponent. myComponent forwards the request to the PXE BPEL engine and waits for a response. In other words, JMSClient places a book order and myComponent receives the order and then sends it to the Webservice that takes orders. The client, JMSClient, and the binding component, myComponent, communicate via JMS; this communication is external to the ServiceMix JBI. myComponent and the PXE BPEL service engine communicate internally over the Normalized Message Router (NMR).

Prerequisites to Run the BPEL Example

The following must be installed to run this example:

  • Java Standard Edition 5.0
  • Ant - http://ant.apache.org
  • PXE - We support WS-BPEL via the PXE BPEL Engine from FiveSight.

    Warning
    titleWarning

    NOTE: ServiceMix works on any Java SE 1.4 or later environment; however to use PXE a Java SE 5 or later platform is required. Before running this example, use Java 1.5 to start up ServiceMix.

Running the BPEL Example

Before running this example, the following setup must be done. PXE has a JBI component and deployment unit, which can be auto-deployed in any JBI compliant container, in this case ServiceMix. To use PXE with ServiceMix, the PXE deployment unit must be placed in the install directory so it will be auto-deployed in ServiceMix. NOTE: The PXE deployment unit has already been placed into the install directory for you - take a look at the servicemix_install_dir\examples\bpel\install directory to see the PXE jar file.

Perform the following steps to run the BPEL example:

  1. From a command shell, go to the BPEL example directory:
    Code Block
    
    cd [servicemix_install_dir]\examples\bpel
    
    where servicemix_install_dir is the directory in which ServiceMix was installed.
  2. Then type:
    Code Block
    
    [servicemix_install_dir]\bin\servicemix servicemix.xml
    
    OR
    
    ..\..\bin\servicemix servicemix.xml
    

  3. To trigger the BPEL business process, send it some messages. To do this, compile and run a simple JMS client. The client is built and run from source code using Ant. Execute Ant from the BPEL directory: servicemix_install_dir\examples\bpel. To run the JMS client type:
    Code Block
    
    ant
    

    Ant will compile and run the simple JMS client, JMSClient, which performs a JMS based request-response into the ServiceMix container before returning the results to the console.

Stopping the BPEL Example

To terminate the BPEL example type "CTRL-C" in the command shell in which it is running and answer "y" to the "Terminate batch job (y/n)?" question.

How it Works

The diagram below illustrates the logical flow of the program through the BPEL components:



Panel
borderColor#ccc
titleBPEL Logical Flow Diagram
borderStylesolid

Image Added



The logical flow of the program is:

  1. The JMSClient, through ActiveMQConnectionFactory, connects to the topic named "demo.org.servicemix.source" and sends a text message containing the message.soap file.
  2. myComponent, being a subscriber of the topic "demo.org.servicemix.source," receives the message.
  3. The myComponent implementation class, JmsServiceComponent, sends the message over the ServiceMix bus to the PxeBpelEngine by executing its onMessage() method. The destinationService property defines the destination of the message. NOTE: the destinationService property is found in the servicemix.xml file.
  4. PxeBpelEngine sends a response back to myComponent through the ServiceMix bus, the NMR.
  5. myComponent uses the jmsTemplate bean to publish the message.
  6. jmsTemplate uses the jmsFactory bean to get a connection to the port associated with the JMS topic called "demo.org.servicemix.source." The message is published on the "demo.org.servicemix.source" topic.
  7. JMSClient, being a subscriber of topic "demo.org.servicemix.source," receives the message.
  8. The response is printed on the console.

Logging information is written to the console as files are transmitted. Typical output looks like the following:

Code Block

 
 
ServiceMix ESB: 1.0

Loading ServiceMix from file: servicemix.xml
[INFO] XmlBeanDefinitionReader - -Loading XML bean definitions from file C:\exist\servicemix\servicemix-1.0.1\examples\bpel\servicemix.xml]
[INFO] CollectionFactory - -JDK 1.4+ collections available
[INFO] CollectionFactory - -Commons
Code Block

dir [servicemix_install_dir]\examples\file-binding\outbox

If you would like to see more files moved from inbox to outbox, copy another file into the inbox directory. The BPEL program continually polls (every 1000 ms) for new files, so any new file placed in inbox, will be transmitted to outbox.

Stopping the BPEL Example

To terminate the BPEL example type "CTRL-C" in the command shell in which it is running and answer "y" to the "Terminate batch job (y/n)?" question.

How it Works

The diagram below illustrates the logical flow of the program through the BPEL components.

Panel
borderColor#ccc
titleBPEL Logical Flow Diagram
borderStylesolid

Image Removed

The logical flow of the program is:

  1. The filePoller polls the inbox directory every 1000 ms looking for a file.
  2. Once a file appears in the inbox directory, the filePoller gets a thread from the workManager. The thread will be used to process the file.
  3. The filePoller creates a normalized message that contains the file to be transmitted. It sends the normalized message to the NMR. The NMR routes the message to the fileSender component.
  4. The fileSender transforms the normalized message back into a file and "sends" it (places it) to the outbox directory.

Logging information is written to the console as files are transmitted. Typical output looks like the following:

Code Block

 
 
ServiceMix ESB: 1.0.1

Loading ServiceMix from file: servicemix.xml
[INFO] XmlBeanDefinitionReader - -Loading XML bean definitions from file [C:\Program Files\servicemix-1.0.1\examples\file-binding\servicemi.xml]
[INFO] FileSystemXmlApplicationContext - -Bean factory for application context [org.springframework.context.support.FileSystemXmlApplication
Context;hashCode=7486844]: org.springframework.beans.factory.support.DefaultListableBeanFactory defining beans [workManager,jbi]; root of BeanFactory hierarchy
[INFO] FileSystemXmlApplicationContext - -2 beans defined in application context 
[org.springframework.context.support.FileSystemXmlApplicationContext;hashCode=7486844]
[INFO] CollectionFactory - -JDK 1.4+ collections available
[INFO] CollectionFactory - -Commons Collections 3.x available
[INFO] FileSystemXmlApplicationContext - -UnableBean tofactory locatefor MessageSourceapplication with name 'messageSource': using default context 
[org.springframework.conte
xtcontext.support.DelegatingMessageSource@1d6776d]
[INFO] FileSystemXmlApplicationContext - -Unable to locate ApplicationEventMulticaster with name 'applicationEventMulticaster': using defaul
tFileSystemXmlApplicationContext;hashCode=110
2920]: org.springframework.beans.factory.support.DefaultListableBeanFactory defining beans 
[jndi,broker,transactionManager,jmsFactory,jbi];
 root of BeanFactory hierarchy[INFO] FileSystemXmlApplicationContext - -5 beans defined in application context
 [org.springframework.context.event.SimpleApplicationEventMulticaster@4fce71support.FileSystemXmlApplicationContext;hashCode=1102920]
[INFO] DefaultListableBeanFactoryFileSystemXmlApplicationContext - -Pre-instantiating singletons in factory Unable to locate MessageSource with name 'messageSource': using default 
[org.springframework.beans.factorycontext.support.DefaultListableBeanF
actory defining beans [workManager,jbi]; root of BeanFactory hierarchyDelegatingMessageSource@18e2b22]
[INFO] DefaultListableBeanFactoryFileSystemXmlApplicationContext - -CreatingUnable sharedto instancelocate ofApplicationEventMulticaster singletonwith beanname 'workManager'applicationEventMulticaster': 
using default [org.springframework.context.event.SimpleApplicationEventMulticaster@13caecd]
[INFO] DefaultListableBeanFactory - -CreatingPre-instantiating sharedsingletons instancein of singleton bean 'jbi'
Created MBeanServer with ID: 203c31:106bd250a5b:-7fff:Lisas:1factory
 [org.springframework.beans.factory.support.DefaultListableBeanFactory 
defining beans [jndi,broker,transactionManager,jmsFactory,jbi]; root of BeanFactory hierarchy]
[INFO] SpringInitialContextFactoryDefaultListableBeanFactory - -LoadingCreating JNDIshared contextinstance from:of class path resource [jndi.xml]singleton bean'jndi'
[INFO] DefaultListableBeanFactory - -Creating shared instance of singleton bean 'broker'
[INFO] XmlBeanDefinitionReaderSpringBrokerContainerFactory - -Loading XMLActiveMQ beanbroker definitionsfrom fromconfiguration: class path resource [jndiactivemq.xml]
[INFO] XmlBeanFactoryActiveMQBeanDefinitionReader - -CreatingLoading XML sharedbean instancedefinitions offrom singletonclass bean 'jndi'
RMIConnectorServer started at: service:jmx:rmi://lisas/jndi/rmi://localhost:1099/defaultJBIJMXpath resource [activemq.xml]
[INFO] JBIContainerActiveMQBeanFactory - -ServiceMixCreating JBIshared Container (http://servicemix.org/) name: defaultJBI running version: ServiceMix.instance of singleton bean 'broker'
[INFO] JBIContainerActiveMQBeanFactory - -Activating component for: [container=defaultJBI,name=fileSender,id=fileSender] with service: fileSender component: org.servicemix.components.file.FileWriter@b1cc87Creating shared instance of singleton bean 'memoryManager'
[INFO] ActiveMQBeanFactory - -Creating shared instance of singleton bean 'derby-ds'
[INFO] ComponentContextImplActiveMQBeanFactory - -Component:Creating fileSendershared activatedinstance endpoint:of fileSendersingleton : fileSenderbean 'mysql-ds'
[INFO] JBIContainerBrokerContainerImpl - -Activating component for: [container=defaultJBI,name=filePoller,id=filePoller] with service: filePoller component: or
g.servicemix.components.file.FilePoller@183e7deActiveMQ 3.1-M6 JMS Message Broker (ID:el2tong-1095-1129854563062-0:0) is starting
[INFO] ComponentContextImplBrokerContainerImpl - -Component:For filePollerhelp activated endpoint: filePoller : filePolleror more information please see: http://www.logicblaze.com
[INFO] DeliveryChannelJDBCPersistenceAdapter - -default destination serviceName for filePoller = fileSender

Note: In the servicemix.xml file, the "destinationService" attribute of the filePoller component is "foo:fileSender." The last line of output (above) shows the NMR using that to deliver the normalized message to fileSender.

Details

...

Component or Bean ID

Description

filePoller

This component periodically checks the "inbox" directory looking for files. If there is a file or directory present, it adds the file to the "workingSet", which is a collection of files to be processed. The workManger is invoked to schedule the work of processing the file from the workingSet. Another thread is created and the processing of the file begins. Processing consists of marshalling the file (streaming it from disk into a normalized message). The normalized message is sent over the NMR to the fileSender component per the specified "destinationService". The destinationService is specified in the servicemix.xml file as an attribute the filePoller component. In this example, the "destinationService" is the fileSender component. Finally, after it has been processed, the filePoller deletes the file from the source directory.

fileSender

This component is the "destinationService" for the filePoller. It receives normalized messages from filePoller. The messages it receives are the files that filePoller has transferred to it via the NMR. It converts the normalized message to its original file format and sends it to the destination directory, the outbox directory. This component creates the filename to which to copy the file by concatenating the string "sample_" with the process id following by ".xml". The concatenated string is passed to the org.servicemix.expression.JaxenStringXPathExpression bean as an argument to the constructor, as can be seen by the constructor-arg value tag in the XML file.

workManager

This bean is used by the filePoller to increase the throughput of the application. The workManager is a thread pool whose size can be adjusted declaratively in the servicemix.xml file. The other components in the BPEL application ask the workManager for threads as needed. For example, threads are used by this application to periodically (every second) check for files in the inbox. Other threads are used to do the work of processing files (streaming them in, normalizing them, and sending them to the NMR). Note: The fileSender component also uses a thread to do its' work, however, it is not using a thread from the workManager's thread pool.

Useful Code Hints

This section describes the start-up sequence and how the ServiceMix container interacts with the BPEL application. The Java class files are located in the servicemix-1.0.1.jar file in the ServiceMix installation directory. To look at the Java source code, unjar and decompile the .class files or download the source code. Please note: the downloadable source code is slightly different than the compiled binary code.

Viewing the Java source code is recommended for understanding the information in this section.

filePoller Details

  1. The ServiceMix container reads the servicemix.xml file and sees it needs to instantiate a FilePoller.
  2. The container calls the init() method of FilePoller, as well as the init() methods of its parents.
  3. The container determines that FilePoller is an MBean and, therefore, calls the start() method of FilePoller, which it inherits from its parent PollingComponentSupport.
  4. The start() method will: (See: PollingComponentSupport.java code fragment below)
    A. Create a timerTask.
    B. Schedule the timerTask at a fixed rate. The start() method uses the "timer" (created in the init method) to schedule the timerTask at a fixed rate: timer.scheduleAtFixedRate(timerTask, firstTime, period). Recall "period" is a property of FilePoller. It was assigned the value of 1000ms by dependency injection from the servicemix.xml file.
    C. timer will call the run() method of the timerTask periodically. timerTask's run method() is defined inline. This run() method will get the workManager object (see below for details).
    D. The workManager will call "scheduleWork(PollingComponentSupport.this)". Note: it passes in PollingComponent support, which by virtue of its inheritance hierarchy, is of type "Work", which is a "Runnable" object.
    E. "workManager.scheduleWork(Work)" will get a Thread, passing in a Runnable object, i.e. PollingComponentSupport, and call its run() method.
    F. PollingComponent's run() method calls poll(), which is implemented in FilePoller.
    G. From this point on the call sequence can be followed in FilePoller...
    H. The start() method of PollingComponentSupport, will eventually call super.start(), which propagates up to call the start() method of BaseLifeCycle, which sets the component state to "RUNNING."

Eventually, one of the threads that is polling (see step G) for a file in the inbox directory will see a one. It will use workManager's thread pool to get a thread for processing the file. Processing the file consists of streaming it from inbox, creating a normalized message, and sending the message to the NMR.

Code Block
titlePollingComponentSupport.java
borderStylesolid

  timerTask = new TimerTask() {
     public void run() {
          try {
                getWorkManager().scheduleWork(PollingComponentSupport.this);
          }
          catch (Throwable e) {
                log.error("Failed to schedule work: " + e, e);
          }
     }
  };
  if (firstTime != null) {
     timer.scheduleAtFixedRate(timerTask, firstTime, period);
  }
  else {
     timer.scheduleAtFixedRate(timerTask, delay, period);
  }
}
super.start();

workManager Details

workManager is a property of the FilePoller object. This property is defined by a local reference, the "ref" attribute in the servicemix.xml file. The local reference is a bean which instantiates org.activemq.work.SpringWorkManager.

The SpringWorkManager is a Spring bean. By default when a Spring bean starts, the properties are set, and then the afterPropertiesSet() method is called by the container.

The workManager is used to allocate threads. The FilePoller asks for threads from the workManager for two operations:

  1. The timerTask uses threads from the thread pool to periodically check the inbox directory for files.
  2. The workManager will also allocate a thread to process a file (read, normalize and send to NMR). The workManager calls a scheduleWork() method which is non-blocking. Therefore, if multiple files need to be processed, FilePoller can continue making requests to the workManager to schedule work.

...

Database driver recognized: [apache_derby_embedded_jdbc_driver]
[INFO] DefaultJDBCAdapter - -Could not create JDBC tables; they could already exist. Failure was: 
CREATE TABLE ACTIVEMQ_MSGS(ID INTEGER NOT NULL, CONTAINER VARCHAR(250), MSGID VARCHAR(250), MSG BLOB, PRIMARY KEY ( ID ) ) 
Message: Table/View 'ACTIVEMQ_MSGS' already exists in Schema 'APP'. SQLState: X0Y32 Vendor code: 20000
[INFO] DefaultJDBCAdapter - -Could not create JDBC tables; they could already exist. Failure was: 
CREATE TABLE ACTIVEMQ_TXS(XID VARCHAR(250) NOT NULL, PRIMARY KEY ( XID )) Message: Table/View 'ACTIVEMQ_TXS' already exists in Schema 'APP'. SQLState: X0Y32 Vendor code: 20000
[INFO] DefaultJDBCAdapter - -Could not create JDBC tables; they could already exist. Failure was: 
CREATE TABLE ACTIVEMQ_ACKS(SUB VARCHAR(250) NOT NULL, CONTAINER VARCHAR(250) NOT NULL, LAST_ACKED_ID INTEGER, SE_ID INTEGER, 
SE_CLIENT_ID VARCHAR(250), SE_CONSUMER_NAME VARCHAR(250), SE_SELECTOR VARCHAR(250), PRIMARY KEY (
 SUB, CONTAINER )) Message: Table/View 'ACTIVEMQ_ACKS' already exists in Schema 'APP'. SQLState: X0Y32 Vendor code: 20000
[INFO] DefaultJDBCAdapter - -Could not create JDBC tables; they could already exist. Failure was: 
ALTER TABLE ACTIVEMQ_MSGS ADD EXPIRATION BIGINT Message: Column 'EXPIRATION' already exists in Table/View 'APP.ACTIVEMQ_MSGS'. SQLState: X0Y32 Vendor code: 20000
[INFO] JournalPersistenceAdapter - -Opening journal.
[INFO] JournalPersistenceAdapter - -Opened journal: Active Journal: using 2 x 20.0 Megs at: ..\var\journal
[INFO] JournalPersistenceAdapter - -Journal Recovery Started.
[INFO] JournalPersistenceAdapter - -Journal Recovered: 0 message(s) in transactions recovered.
[INFO] TcpTransportServerChannel - -Listening for connections at: tcp://el2tong:61616
[INFO] BrokerConnectorImpl - -ActiveMQ connector started: TcpTransportServerChannel@tcp://el2tong:61616
[INFO] BrokerContainerImpl - -ActiveMQ JMS Message Broker (ID:el2tong-1095-1129854563062-0:0) has started
[INFO] DefaultListableBeanFactory - -Creating shared instance of singleton bean 'transactionManager'
[INFO] DefaultListableBeanFactory - -Creating shared instance of singleton bean 'jmsFactory'
[INFO] DefaultListableBeanFactory - -Creating shared instance of singleton bean 'jbi'
[INFO] ActiveMQConnection - -channel status changed: Channel: TcpTransportChannel: Socket[addr=localhost/127.0.0.1,port=61616,localport=1096] has connected
[INFO] BrokerContainerImpl - -Adding new client: ID:el2tong-1095-1129854563062-5:0 on transport: TcpTransportChannel: Socket[addr=/127.0.0.1,port=1096,localport=61616]
[INFO] JBIContainer - -ServiceMix JBI Container (http://servicemix.org/) name: defaultJBI running version: ServiceMix.
[INFO] JBIContainer - -Activating component for: [container=defaultJBI,name=myComponent,id=myComponent]
 with service: {uri:fivesight.com/examples/AsyncProcessJBI}JmsService component: org.servicemix.components.jms.JmsServiceComponent@1b82d69
[INFO] ComponentContextImpl - -Component: myComponent activated endpoint: {uri:fivesight.com/examples/AsyncProcessJBI}JmsService : myComponent

Details

The following table provides more details about the function of each component and bean in the servicemix.xml file:

Component or Bean ID

Description

jbi

jbi is the "id" of the JBI container and provides the basic infrastructure services for myComponent. During initialization, several singletons are instantiated: transactionManager, broker, jmsFactory, and jbi. Also, take note of the properties installationDirPath and deploymentDirPath defined in servicemix.xml. ServiceMix automatically installs components found in the folder specified in the installationDirPath property. It automatically deploys component-specific artifacts found in the folder specified in the deploymentDirPath property.

JMSClient

This Java standalone program, through the ActiveMQConnectionFactory, connects to topic "demo.org.servicemix.source." It then creates a text message from the file message.soap and publishes it to the topic "demo.org.servicemix.source," then requests and waits for a response. It eventually prints the response to the console.

myComponent

This JMS service component subscribes to the "demo.org.servicemix.source" topic via its defaultDestinationName property specified in the servicemix.xml configuration file. Through its template property, it uses jmsFactory to listen on port 61616 via ActiveMQConnectionFactory. It is implemented by the JmsServiceComponent that has an onMessage() method which is called by ActiveMQ when a message arrives on the topic. This method creates a normalized message, which is sent over the ServiceMix bus to the PxeBpelEngine as specified on its destinationService property.

jndi

This bean loads up database and transaction manager resources, which will be used by the other components in the system. More importantly, the JNDI context must be configured so that PXE can be deployed.

Pxe-install.jar

This jarfile is located in the examples\bpel\install directory. It contains many files, which in turn contain the classes that implement the PXE BPEL engine. It also has a jbi.xml file, which is used by ServiceMix to install the PXE BPEL engine as a ServiceMix service-engine component. Note, that in this file the component type is "service-engine" and the component name is PxeBpelEngine. When processes are deployed to the PXE engine (see next row with AsyncProcess-sa.jar), it exposes them as services on the JBI, which can be referenced by other components as destinationService(s), with destinationEnpoint(s) - see the servicemix.xml file.

AsyncProcess-sa.jar

This jarfile is located in the examples\bpel\deploy directory. It contains a jbi.xml file, which references the PxeBpelEngine. This ties the processes to the PXE engine described in the previous section. The jbi.xml file also references the AsyncProcess-su.zip file, which is also contained in the AsycnProcess-sa.jar file. This zipfile contains other configuration files and WSDL files, i.e., pxe-system.xml and resource_X.stream, which describe the services deployed on the PXE engine.

broker

The broker bean uses the activemq.xml file to configure the message broker, which handles the JMS messages for the components that require JMS messaging services.

transactionManager

This bean is configured to be the default transaction manager for the jbi container. This transaction manager provides transactional services between the resource adapter (in this case the ActiveMQ resource adapter provided by the jencks JCA container) and components in the jbi container.

jmsFactory

This bean listens on port 61616 and provides a pooled ActiveMQ connection.

Related Documentation

For more information on the following topics please see: