Overview of the ServiceMix 1.x File Binding Example
This document describes how to run the File Binding example and provides details about what it does. For information on the business use case, please refer to: Use Case for File Binding.
The File Binding example illustrates the following:
- use of declarative programming
- how to interact with the file system
The source code for the File Binding example is located in the ServiceMix installation directory under the examples\file-binding
directory in the servicemix.xml
file. It is recommended that you refer to the source code while reading this document.
The File Binding 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, then retrieves it from there and sends it over the Normalized Message Router (NMR) to another component which deposits the file into an outbox directory. Note: the file to be transmitted must be in XML format.
Running the File Binding Example
From a command shell, go to the File Binding example directory:
cd [servicemix_install_dir]\examples\file-binding
where servicemix_install_dir
is the directory in which ServiceMix was installed.
Before running the example, copy a file into the inbox directory:
copy test-file.xml inbox
Then type:
[servicemix_install_dir]\bin\servicemix servicemix.xml
After a few seconds of running the example, the test-file.xml
file will appear in the outbox directory. To see this open another command window and do a directory listing on the outbox directory:
dir [servicemix_install_dir]\bin\servicemix\examples\outbox
The files
Stopping the File Binding Example
To terminate the File Binding 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 file binding components.
Messages flow through the components as follows:
- The timer component sends a normalized message to inputSender through the Normalized Message Router (NMR).
- inputSender converts the message (marshals it) into a JMS message, then uses the jmsTemplate bean to publish the message.
- 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.
- jencks (the JCA resource adapter) listens on port 61616 for messages.
- inputReceiver subscribes to the "demo.org.servicemix.source" topic via jencks and receives the JMS message.
- inputReceiver normalizes the JMS message and sends it to outputSender via the NMR.
- outputSender marshals the normalized message to a JMS message and uses jmsTemplate to publish the message on the "demo.org.servicemix.result" topic.
- jmsTemplate publishes it on the "demo.org.servicemix.result" topic using jmsFactory to get a connection to the result topic.
- jencks listens on port 61616 for messages.
- jmsTrace subscribes to the "demo.org.servicemix.result" topic and receives the JMS message via jencks.
- jmsTrace converts the JMS message into a normalized message and sends it to trace via the NMR.
- trace transforms the normalized message into a string and logs it to the console.
Every 5 seconds logging information is written to the console, followed by information from the trace component. Note, that the triggers' property values of "name", "My Example Job", "group", and "ServiceMix" are displayed along with a timestamp. Typical output looks like the following:
[INFO] TraceComponent - -Exchange: org.servicemix.jbi.messaging.InOnlyImpl@4fdf11 received IN message: org.servicemix.jbi.messaging.NormalizedMessageImpl@1be0369{properties: {org.servicemix.jms.message=ACTIVEMQ_TEXT_MESSAGE: id = 0 ActiveMQMessage{ , jmsMessageID = null, bodyAsBytes = org.activemq.io.util.ByteArray@1d1fc02, readOnlyMessage = true, jmsClientID = 'ID:Lisas-2828-1126207917359-23:0' , jmsCorrelationID = 'null' , jmsDestination = demo.org.servicemix.result, jmsReplyTo = null, jmsDeliveryMode = 2, jmsRedelivered = false, jmsType = 'null' , jmsExpiration = 0, jmsPriority = 4, jmsTime stamp = 1126207938593, properties = {}, readOnlyProperties = true, entryBrokerName = 'ID:Lisas-2828-1126207917359-0:0' , entryClusterName = 'default' , consumerNos = [0], transactionId = 'null' , xaTransacted = false, consumerIdentifer = 'ID:Lisas-2828-1126207917359-14:0' , messageConsumed = false, transientConsumed = true, sequenceNumber = 7, deliveryCount = 1, dispatchedFromDLQ = false, messageAcknowledge = org.activemq.ActiveMQSession@1de7497, jmsMessageIdentity = null, producerKey = ID:Lisas-2828-1126207917359-29: }, text = <?xml version="1.0" encoding="UTF-8"?> <timer><name>My Example Job</name><group>ServiceMix</group><fullname>ServiceMix.My Example Job</fullname><description/><fireTime> Thu Sep 08 12:32:18 PDT 2005</fireTime></timer>}}
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 |
---|---|
filePoller |
periodically checks the "inbox" directory and recursively scans the inbox directory and subdirectories for new files. If there is a file present, it adds the file to the "workingSet" of the workManager. The workManger dispatches to a worker thread, which calls back into the filePoller to process a file from the workingSet. Processing consists of marshalling the file (streaming it from disk into a normalized message). The normalized message is sent over the Normalized Message Router (NMR) to the fileSender component per the specified "destinationService" which is specified in the |
fileSender |
this component listens for normalized messages. 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 by processing it and sending it to the destination directory, in this case the outbox directory. |
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 workManager processes the workingSet. The workingSet is the collection of files to be transfered over the NMR. The workManager continually dispatches a unit of work, i.e., a file transfer, to one of the threads in its pool, until the workingSet has been fully transfered. |
Related Documentation
For more information on the following topics please see:
- For details on the tags and attributes of the XML file (servicemix.xml), please see the description of the xsd file at: link to xsd description file.