Versions Compared

Key

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

Overview of the ServiceMix 1.x Basic Example

This document describes how to run the Basic example is used and provides details about what it does.
The source code for the Basic example is stored in the Service Mix installation directory under the examples\basic directory in the servicemix.xml file. For information on the business use case, please refer to: pagetobecreated.

The Basic example illustrates the following concepts:

  • use of declarative programming
  • how to use an ActiveMQ message broker
  • how to use a Quartz timer
  • how to use the jencks Jencks JCA container
  • how to use a transaction managerthe Geronimo Transaction Manager via the Jencks factory bean
  • how to using use tracing

The example has several components. source code for the Basic example is located in the ServiceMix installation directory under the examples\basic directory in the servicemix.xml file. It is recommended that you refer to the source code while reading this document.

There are several components in the servicemix.xml file. One component sets off a timer trigger to send messages to a source destination. Then those messages are consumed by another component and sent to a different output destination - along with a . A trace component displaying displays the output messages as they arrive.

Running the Basic Example

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

Code Block

cd [servicemix_install_dir]\examples\basic

Then type:

Code Block

[servicemix_install_dir]\bin\servicemix servicemix.xml

where servicemix_install_dir is the directory in which Service Mix was installed.

Stopping the Basic Example

To terminate the Basic 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 flow of messages through the Basic components.

Panel
borderColor#ccc
titleBasic Example Message Flow Diagram
borderStylesolid

Image Added



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:

Code Block

 
 
[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 This demonstrates a simple JMS bridge in action along with timers and tracing.
The diagram illustrates the components of the Basic example and how they interact with each other within the JBI container.
A DIAGRAM WILL BE PUT HERE--still creating
The following table explains the basic function of each component and bean in the servicemix.xml file.

Component or Bean ID

Description

jbiThe

jbi container contains jbi is the "id" of the JBI container and provides the basic infrastructure services for the following components: timer, inputSender, inputReceiver, outputSender, jmsTrace, and trace. First the servicemix.xml file initializes the jbi container by setting several properties. Then the components are run. Note: During the initialization, a bean called "transactionManager" is instantiated. The transactionManager provides the connectivity between the JMS messaging system and the jbi container. During initialization, several singletons are instantiated: transactionManager, broker, jencks, jmsFactory, and jbi. After initialization, the components in the jbi container are activated, starting with the timer component.

timer

The timer component shows the use of the QuartzComponent class.

timer

Every 5 seconds, until the program is terminated, the timer component kicks off a triggeran instance of a SimpleTrigger, which is associated with an instance of JobDetail. The job has a property called "name" with a value of "My Example Job" and another property called "group" with a value of "ServiceMix." The trigger resulting message is converted to a normalized message and routed through the Normalized Message Router ( NMR).

inputSender

Receives This is a component inside the JBI container. It receives the normalized message (the message from the trigger), converts it to a JMS message, and publishes it to the topic called demo.org.servicemix.source. It uses the jmsTemplate 1 bean to handle the publish.

inputReceiver

This component uses the bean called jencks , which is a the JCA container, to listen on port 61616 for a JMS message on the topic called "demo.org.servicemix.source." Essentially, inputReceiver subscribes to the demo.org.servicemix.source topic. It takes the message, normalizes it, and routes it to outputSender via the NMR. This component combined with outputSender and some supporting beans creates a JMS bridge between two topics.

outputSender

This component receives a normalized message from the NMR, marshals it into a JMS message using jmsTemplate, then publishes it on the ActiveMQ (JMS) topic called "demo.org.servicemix.result."

jmsTrace

This component uses the jencks bean to subscribe to the "demo.org.servicemix.result" topic and get the message that is theremessages. It then marshals the message into a Normalized Message normalized message and routes it via the NMR to the trace component.

trace

jmsTrace

This component uses jencks to listen to port 61616 for the purposes of tracing the messages received on that port.

trace

 

 

 

 

 

Receives normalized messages from jmsTrace via the NMR. It transforms the normalized message into a string and logs it to the console.

jencks

The jencks bean defines a JCA container. This bean has two properties, one of which is an ActiveMQ listener, which . The JCA container allows you to configure thread pool size, configure a transaction manager, and configure a resource adapter. In this example, the resource adapter is an ActiveMQ adapter, however, another JMS listener could be configured instead. This adapter listens on port 61616 for JMS messages.

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 invoked in configured to be the default transaction manager for the jbi containers initialization. It instantiates the
org.jencks.factory.TransactionManagerFactoryBean which .... container. jencks is configured to use the default transaction manager. 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 the jbi container.

jmsFactory

This bean listens on port 61616 .

When running the Basic example, the typical output looks like the following. Note, that the triggers property values of "name", "My Example Job", "group", and "ServiceMix" are displayed along with a timestamp.

PUT PIC of OUTPUT HERE.

Interesting Details

...

and provides a pooled ActiveMQ connection.

1. jmsTemplate: JmsTemplate is a Spring component which hides the low level details when sending JMS messages. For additional information see: JmsTemplate. jmsTemplate is not a component in the jbi container. It is used by inputSender and outputSender.

Related Documentation

For more information on the following topics please see:

Running the Basic Example

To run Basic:
From a command shell, go to the Basic example directory:

Code Block

cd [servicemix_install_dir]\examples\basic

To run it:

Code Block

[servicemix_install_dir]\bin\servicemix servicemix.xml

...

Stopping the Basic Example

...

Related Documentation

...