You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 20 Next »

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.



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.

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.



Basic Example Message Flow Diagram



Messages flow through the components as follows:

  1. The timer component sends a normalized message to inputSender through the Normalized Message Router (NMR).
  2. inputSender converts the message (marshals it) into a JMS message, then uses the jmsTemplate bean to publish the message.
  3. 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.
  4. jencks (the JCA resource adapter) listens on port 61616 for messages.
  5. inputReceiver subscribes to the "demo.org.servicemix.source" topic via jencks and receives the JMS message.
  6. inputReceiver normalizes the JMS message and sends it to outputSender via the NMR.
  7. outputSender marshals the normalized message to a JMS message and uses jmsTemplate to publish the message on the "demo.org.servicemix.result" topic.
  8. jmsTemplate publishes it on the "demo.org.servicemix.result" topic using jmsFactory to get a connection to the result topic.
  9. jencks listens on port 61616 for messages.
  10. jmsTrace subscribes to the "demo.org.servicemix.result" topic and receives the JMS message via jencks.
  11. jmsTrace converts the JMS message into a normalized message and sends it to trace via the NMR.
  12. 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 subdirectories for new files. If there is a file present, it converts the file into a normalized message and sends it over the Normalized Message Router (NMR) to the fileSender component.

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.



  • No labels