Overview of the Basic Example
This document describes how to run the Basic example and provides details about what it does.
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
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. It is helpful to look at the source code while reading this description.
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
From a command shell, go to the Basic example directory:
cd [servicemix_install_dir]\examples\basic
Then type:
[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.
How it Works
The diagram illustrates the flow of messages through the Basic 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.
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.
[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>}}
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 the following components: timer, inputSender, inputReceiver, outputSender, jmsTrace, and trace. 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 |
Every 5 seconds, until the program is terminated, the timer component kicks off an instance of a SimpleTrigger. 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 NMR. |
inputSender |
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 bean to handle the publish. |
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. |
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. 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 ... |
transactionManager |
This bean is invoked in the jbi container's initialization. It instantiates |
jmsFactory |
This bean listens on port 61616. |
Related Documentation
Please see ..., plus Jira XX for details on fields...