Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

This document describes how 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.

...

{Note: It is helpful to look at the source code while reading this description

...

.

...


...


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 JCA container

...

  • how to use a JOTM transaction manager

...

  • how to use tracing

There are several components in the servicemix.xml file. One component sets off a 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 trace component displaying the output messages as they arrive. This demonstrates a simple JMS bridge in action along with timers and tracing.

...



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

...



Then

...

type:

Code Block
[servicemix_install_dir]\bin\servicemix servicemix.xml

...

code


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.

...



How it Works

The diagram 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 (NM) 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 factory to the port associated with the JMS topic called "demo.org.servicemix.source."

...

  1. The

...

  1. message

...

  1. is

...

  1. published

...

  1. on

...

  1. the

...

  1. "demo.org.servicemix.source"

...

  1. topic.

...

  1. jencks listens on port 61616 for messages.
  2. inputReceiver subscribes to the "demo.org.servicemix.source"

...

  1. topic

...

  1. via

...

  1. the

...

  1. jencks

...

  1. bean

...

  1. and

...

  1. receives

...

  1. the

...

  1. JMS

...

  1. message.

...

  1. inputReceiver normalizes the JMS message and sends it to outputSender via the NMR.
  2. outputSender marshals the NM to a JMS message and uses jmsTemplate to publish the message on the "demo.org.servicemix.result"

...

  1. topic.

...

  1. jmsTemplate publishes it on the "demo.org.servicemix.result"

...

  1. topic

...

  1. using

...

  1. jmsFactory

...

  1. to

...

  1. get

...

  1. a

...

  1. connection

...

  1. factory

...

  1. to

...

  1. the

...

  1. result

...

  1. topic.

...

  1. jencks listens on port 61616 for messages.
  2. jmsTrace, via jencks, subscribes to the "demo.org.servicemix.result"

...

  1. topic

...

  1. and

...

  1. receives

...

  1. the

...

  1. JMS

...

  1. message.

...

  1. jmsTrace converts the JMS message into a normalized message and sends it to trace via the NMR.
  2. trace transforms the normalized message into a string and logs it to the console.

Typical output looks like the following. 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.

Code Block

[INFO] TraceComponent - -Exchange: org.servicemix.jbi.messaging.InOnlyImpl@b55129 received IN message:

...

 
org.servicemix.jbi.messaging.NormalizedMessageImpl@8c9b49{properties: {org.servicemix.jms.message=ACTIVEMQ_TEXT_MESSAGE: id = 0 ActiveMQMessage

...


{ , jmsMessageID = ID:redmac-2.local-50615-1123857186823-29:1, bodyAsBytes = org.activemq.io.util.ByteArray@b1a22,

...

 
readOnlyMessage = true, jmsClientID = 'ID:redmac-2.local-50615-1123857186823-22:0' , jmsCorrelationID = 'null' ,

...

 
jmsDestination = demo.org.servicemix.result, jmsReplyTo = null, jmsDeliveryMode = 2, jmsRedelivered = false, jmsType = 'null'

...

 
, jmsExpiration = 0, jmsPriority = 4, jmsTimestamp = 1123857193312, properties = {}, readOnlyProperties = true, entryBrokerName =

...

 
'ID:redmac-2.local-50615-1123857186823-0:0' , entryClusterName = 'default' , consumerNos = [0], transactionId = 'null' ,

...


 xaTransacted = false, consumerIdentifer = 'ID:redmac-2.local-50615-1123857186823-14:0' , messageConsumed = false,

...

 
transientConsumed = true, sequenceNumber = 1, deliveryCount = 1, dispatchedFromDLQ = false, messageAcknowledge =

...

 
org.activemq.ActiveMQSession@74b5ee, jmsMessageIdentity = null, producerKey = ID:redmac-2.local-50615-1123857186823-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>Fri Aug 12 15:33:12 BST 2005</fireTime></timer>}}
Code Block

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

The jbi container contains the following components: timer, inputSender, inputReceiver, outputSender, jmsTrace, and trace. First the servicemix.xml file initializes the jbi container by setting several properties. During the initialization, a bean called "transactionManager" is instantiatedseveral singletons are instantiated: transactionManager , broker,jencks, jmsFactory, and _jbi: . After initialization, the components in servicemix.xml begin running.

transactionManager

The transactionManager provides ... to the JBI container.

timer

Every 5 seconds, until the program is terminated, the timer component kicks off a trigger. 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 is converted to a normalized message and routed through the Normalized Message Router (NMR).

inputSender

Receives the normalized message (the trigger), converts it to a JMS message, and publishes it to the topic called demo.org.servicemix.source.

inputReceiver

This component uses the bean called jencks , which is a 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 there. It then marshals the message into a Normalized Message and routes it via the NMR to the trace component.

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

 

 

 

 

jencks

The jencks bean defines a JCA container. This bean has two properties, one of which is an ActiveMQ listener, which listens on port 61616. In general a JCA container must provide threading, The JCA

broker

The broker bean ...

transactionManager

This bean is invoked in the jbi containers initialization. It instantiates the
org.jencks.factory.TransactionManagerFactoryBean. This bean provides XA transactions between the resource adapter (in this case the ActiveMQ resource adapter) and the jbi container.

jmsFactory

This bean listens on port 61616.

...