Versions Compared

Key

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

...

The source code for the JMS Binding example is located in the ServiceMix installation directory under the examples\jms-binding directory in the servicemix.xml file. It is recommended that you refer to the source code while reading this document.

This example shows how to connect the JMS bindings to a simple service component. One component listens for a JMS message on topic 'demo.org.servicemix.source' while another publishes processed messages to topic 'demo.org.servicemix.result'.



Running the JMS Binding Example

  1. From a command shell, go to the Basic example directory:
    Code Block
    cd [servicemix_install_dir]\examples\jms-binding
    
    where servicemix_install_dir is the directory in which ServiceMix was installed.
  2. Then type:
    Code Block
    [servicemix_install_dir]\bin\servicemix servicemix.xml
    
  3. To start the sending and receiving of messages from the JMS topics, send it some messages. To do this, compile and run a simple JMS client. The client is built and run from source code using Ant. Execute Ant from the JMS Binding directory: servicemix_install_dir\examples\jms-binding. To run the JMS client type:
    Code Block
    ant
    

    Ant will compile and run the simple JMS client, JMSClient, which performs a JMS based request-response into the ServiceMix container before returning the results to the console.

Stopping the

...

JMS Binding Example

To terminate the Basic JMS 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.

...

  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

 
 
Loading ServiceMix from file: C:\exist\servicemix\servicemix-1.0.1\examples\jms-binding\servicemix.xml
[INFO] XmlBeanDefinitionReader - -Loading XML bean definitions from file [C:\exist\servicemix\servicemix-1.0.1\examples\jms-binding\servicemix.xml]
[INFO] FileSystemXmlApplicationContext - -Bean factory for application context 
[org.springframework.context.support.FileSystemXmlApplicationContext;hashCode=1102920]: org.springframework.beans.factory.support.DefaultListableBeanFactory defining beans [jencks,broker,transactionManager,jmsFactory,jbi]; root of BeanFactory hierarchy
[INFO] FileSystemXmlApplicationContext - -5 beans defined in application context [org.springframework.context.support.FileSystemXmlApplicationContext;hashCode=1
102920]
[INFO] CollectionFactory - -JDK 1.4+ collections available
[INFO] CollectionFactory - -Commons Collections 3.x available
[INFO] FileSystemXmlApplicationContext - -Unable to locate MessageSource with name 'messageSource': using default [org.springframework.context.support.Delegatin
gMessageSource@1971afc]
[INFO] FileSystemXmlApplicationContext - -Unable to locate ApplicationEventMulticaster with name 'applicationEventMulticaster': using default [org.springframewo
rk.context.event.SimpleApplicationEventMulticaster@cdedfd]
[INFO] DefaultListableBeanFactory - -Pre-instantiating singletons in factory [org.springframework.beans.factory.support.DefaultListableBeanFactory defining bean
s [jencks,broker,transactionManager,jmsFactory,jbi]; root of BeanFactory hierarchy]
[INFO] DefaultListableBeanFactory - -Creating shared instance of singleton bean'jencks'
[INFO] DefaultListableBeanFactory - -Creating shared instance of singleton bean'broker'
[INFO] SpringBrokerContainerFactory - -Loading ActiveMQ broker from configuration: class path resource [activemq.xml]
[INFO] ActiveMQBeanDefinitionReader - -Loading XML bean definitions from class path resource [activemq.xml]
[INFO] ActiveMQBeanFactory - -Creating shared instance of singleton bean 'broker'
[INFO] ActiveMQBeanFactory - -Creating shared instance of singleton bean 'memoryManager'
[INFO] ActiveMQBeanFactory - -Creating shared instance of singleton bean 'derby-ds'
[INFO] ActiveMQBeanFactory - -Creating shared instance of singleton bean 'mysql-ds'
[INFO] BrokerContainerImpl - -ActiveMQ 3.1-M6 JMS Message Broker (ID:el2tong-3108-1131439169538-0:0) is starting
[INFO] BrokerContainerImpl - -For help or more information please see: http://www.logicblaze.com
[INFO] JDBCPersistenceAdapter - -Database driver recognized: [apache_derby_embedded_jdbc_driver]
[INFO] DefaultJDBCAdapter - -Could not create JDBC tables; they could already exist. Failure was: CREATE TABLE ACTIVEMQ_MSGS(ID INTEGER NOT NULL, CONTAINER VARC
HAR(250), MSGID VARCHAR(250), MSG BLOB, PRIMARY KEY ( ID ) ) Message: Table/View 'ACTIVEMQ_MSGS' already exists in Schema 'APP'. SQLState: X0Y32 Vendor code: 20000
[INFO] DefaultJDBCAdapter - -Could not create JDBC tables; they could already exist. 
Failure was: CREATE TABLE ACTIVEMQ_TXS(XID VARCHAR(250) NOT NULL, PRIMARY KEY ( XID )) Message: Table/View 'ACTIVEMQ_TXS' already exists in Schema 'APP'. S
QLState: X0Y32 Vendor code: 20000
[INFO] DefaultJDBCAdapter - -Could not create JDBC tables; they could already exist. Failure was: CREATE TABLE ACTIVEMQ_ACKS(SUB VARCHAR(250) NOT NULL, CONTAINE
R VARCHAR(250) NOT NULL, LAST_ACKED_ID INTEGER, SE_ID INTEGER, SE_CLIENT_ID VARCHAR(250), SE_CONSUMER_NAME VARCHAR(250), SE_SELECTOR VARCHAR(250), PRIMARY KEY (
 SUB, CONTAINER )) Message: Table/View 'ACTIVEMQ_ACKS' already exists in Schema 'APP'. SQLState: X0Y32 Vendor code: 20000
[INFO] DefaultJDBCAdapter - -Could not create JDBC tables; they could already exist. Failure was: ALTER TABLE ACTIVEMQ_MSGS ADD EXPIRATION BIGINT Message: 
Column 'EXPIRATION' already exists in Table/View 'APP.ACTIVEMQ_MSGS'. SQLState: X0Y32 Vendor code: 20000
[INFO] JournalPersistenceAdapter - -Opening journal.
[INFO] JournalPersistenceAdapter - -Opened journal: Active Journal: using 2 x 20.0 Megs at: ..\var\journal
[INFO] JournalPersistenceAdapter - -Journal Recovery Started.
[INFO] JournalPersistenceAdapter - -Journal Recovered: 1 message(s) in transactions recovered.
[INFO] TcpTransportServerChannel - -Listening for connections at: tcp://el2tong:61616
[INFO] BrokerConnectorImpl - -ActiveMQ connector started: TcpTransportServerChannel@tcp://el2tong:61616
[INFO] BrokerContainerImpl - -ActiveMQ JMS Message Broker (ID:el2tong-3108-1131439169538-0:0) has started
[INFO] DefaultListableBeanFactory - -Creating shared instance of singleton bean 'transactionManager'
[INFO] DefaultListableBeanFactory - -Creating shared instance of singleton bean 'jmsFactory'
[INFO] DefaultListableBeanFactory - -Creating shared instance of singleton bean 'jbi'
[INFO] JCAConnector - -Activating endpoint for activationSpec: ActiveMQActivationSpec{acknowledgeMode='Auto-acknowledge', destinationType='javax.jms.Topic', mes
sageSelector='null', destination='demo.org.servicemix.source', clientId='null',
subscriptionName='null', subscriptionDurability='NonDurable'} using endpointFact
ory: org.jencks.SingletonEndpointFactory@2803d5[transactionManager=null]
[INFO] ActiveMQConnection - -channel status changed: Channel: TcpTransportChannel: Socket[addr=localhost/127.0.0.1,port=61616,localport=3109] has connected
[INFO] BrokerContainerImpl - -Adding new client: ID:el2tong-3108-1131439169538-6:0 
on transport: TcpTransportChannel: Socket[addr=/127.0.0.1,port=3109,localport=61616]
[INFO] SpringInitialContextFactory - -Loading JNDI context from: class path resource [jndi.xml]
[INFO] XmlBeanDefinitionReader - -Loading XML bean definitions from class path resource [jndi.xml]
[INFO] XmlBeanFactory - -Creating shared instance of singleton bean 'jndi'
[INFO] JBIContainer - -ServiceMix JBI Container (http://servicemix.org/) name: defaultJBI running version: ServiceMix.
[INFO] JBIContainer - -Activating component for: [container=defaultJBI,name=inputReceiver,id=inputReceiver] with service: {http://servicemix.org/demo/}inputRece
iver component: org.servicemix.components.jms.JmsInUsingJCABinding@98f192
[INFO] ComponentContextImpl - -Component: inputReceiver activated endpoint: {http://servicemix.org/demo/}inputReceiver : inputReceiver
[INFO] JBIContainer - -Activating component for: [container=defaultJBI,name=outputSender,id=outputSender] with service: {http://servicemix.org/demo/}outputSende
r component: org.servicemix.components.jms.JmsSenderComponent@1d5b89c
[INFO] ComponentContextImpl - -Component: outputSender activated endpoint: {http://servicemix.org/demo/}outputSender : outputSender
[INFO] JCAContainer - -Jencks JCA Container (http://jencks.org/) has started running version: 1.0-M1
[INFO] BrokerContainerImpl - -Adding new client: ID:el2tong-3114-1131439189647-1:0 on transport: TcpTransportChannel: Socket[addr=/127.0.0.1,port=3115,localport=61616]
[INFO] DeliveryChannel - -default destination serviceName for inputReceiver = {http://servicemix.org/demo/}outputSender
[INFO] ActiveMQConnection - -channel status changed: Channel: TcpTransportChannel: Socket[addr=localhost/127.0.0.1,port=61616,localport=3116] has connected
[INFO] BrokerContainerImpl - -Adding new client: ID:el2tong-3108-1131439169538-17:0 on 
transport: TcpTransportChannel: Socket[addr=/127.0.0.1,port=3116,localport=61616]
[INFO] BrokerContainerImpl - -Removing client: ID:el2tong-3114-1131439189647-1:0 on transport: 
TcpTransportChannel: Socket[addr=/127.0.0.1,port=3115,localport=61616]
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 function of each component and bean in the servicemix.xml file.

...