| By Robert Davies, James Strachan | Article Rating: |
|
| February 25, 2008 06:30 AM EST | Reads: |
17,394 |
So after starting the CamelContext, we can fire some objects into Camel.
In normal use, an external system would be firing messages or events directly into Camel through one if its components but we're going to use the CamelTemplate, which is a really easy way to test your configuration:
CamelTemplate template = new CamelTemplate(context);
We can now send some test messages over JMS using the CamelTemplate:
for (int i = 0; i < 10; i++) {
template.sendBody("test-jms:queue:test.queue", "Test Message: " + i);
}
From the CamelTemplate we send objects (in this case text) into the CamelContext to the Component test-jms:queue:test.queue. These text objects will be converted automatically into JMS Messages and posted to a JMS queue named test.queue. When we set up the route, we configured the FileComponent to listen of the test.queue.
The file FileComponent will take messages from the queue and save them to a directory named test. Every message will be saved in a file that corresponds to its destination and message ID.
Finally, we configured our own listener in the route to take notifications from the FileComponent and print them out as text.
Spring XML Configuration
This example will use
Spring XML configuration to transform files from a directory using
XQuery and send the results to a JMS queue. It parsers some files from
a directory, transforms them using XQuery then sends them to a message
queue. To make it easy to look at the generated files, we also have
another route that consumes from the JMS queue and writes them to an
output directory.
Running the Example
To run the example we use the
Camel Maven Plugin. For example, from the source or binary distribution
the following should work:
cd examples/camel-example-spring-xquery
mvn camel:run
You should now see the generated files in the target/outputFiles directory, which are the transformed messages read from the JMS queue.
Code Walkthrough
What this does is boot up the
Spring ApplicationContext defined in the file
META-INF/spring/camelContext.xml on the classpath. This is a regular
Spring XML document that uses the Camel XML configuration to configure
a CamelContext.
Note that at the end of this XML example file we explicitly configure the ActiveMQ component with details on how to connect to the broker.
The main part of the Spring XML file is here:
<camelContext useJmx="true" xmlns="http://activemq.apache.org/camel/schema/spring">
<!-- lets parse files, transform them with XQuery and send them to JMS -->
<route>
<from uri="file:src/data?noop=true"/>
<to uri="xquery:myTransform.xquery"/>
<to uri="jms:MyQueue"/>
</route>
<!-- now lets write messages from the queue to a directory -->
<route>
<from uri="jms:MyQueue"/>
<to uri="file:target/outputFiles"/>
</route>
</camelContext>
<!-- lets configure the default ActiveMQ broker URL -->
<bean id="jms" class="org.apache.camel.component.jms.JmsComponent">
<property name="connectionFactory">
<bean class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="vm://localhost?broker.persistent=false"/>
</bean>
</property>
</bean>
This hopefully has given you a flavor of how easy it is to do enterprise integration using Apache Camel. For more information see the Web site at http://activemq.apache.org/camel/.
Resources
www.enterpriseintegrationpatterns.com/
Published February 25, 2008 Reads 17,394
Copyright © 2008 SYS-CON Media, Inc. — All Rights Reserved.
Syndicated stories and blog feeds, all rights reserved by the author.
More Stories By Robert Davies
Rob Davies, director of open source development at IONA, has more than 20 years of experience developing high-performance distributed enterprise systems and products for telecom and finance corporations. He is responsible for leading the development of IONA's FUSE family of open source products, which are based on leading projects at the Apache Software Foundation. Rob is a founder of the Apache ActiveMQ, Apache ServiceMix and Apache Camel projects. Prior to joining IONA, Rob served as the founder and vice president of product development at LogicBlaze, which was acquired by IONA in 2007. Previously, Rob served as founder and CTO of integration software developer SpiritSoft.
More Stories By James Strachan
James Strachan, technical director at IONA, is responsible for helping the Company provide open source offerings for organizations requiring secure, high-performance distributed systems and integration solutions. He is heavily involved in the open source community, and has co-founded several Apache projects, including ActiveMQ, Camel, Geronimo and ServiceMix. He also created the "Groovy" scripting language and additional open source projects such as dom4j, jaxen and Jelly. Prior to joining IONA, James spent more than 20 years in enterprise software development. Previously, James co-founded LogicBlaze, Inc., an enterprise open source company acquired by IONA. Prior to that, he founded SpiritSoft, Inc., a company providing enterprise Java middleware services.
- 4th International Cloud Computing Conference & Expo Starts Today
- Deputy CIO of the CIA to Keynote 1st Annual GovIT Expo
- Publishing Synergy: Blog, Twitter and Ulitzer
- Cloud Computing Expo: Exclusive Q&A with Yahoo! SVP Cloud Computing
- Performance Tuning Essentials for Java
- Cloud Expo New York Call for Papers Deadline December 15
- IBM Hardware Chief, Intel VC Exec Arrested in Insider Trading Scam
- Cloud Computing Can Revitalize Your Career as Software Developer
- Open Source Mobile Cloud Sync and Push Email
- SOA World Magazine "Readers' Choice Awards" Voting Is Now Open
- Oracle+MySQL Opponents Take to the Barricades
- SpringSource Moving to Spring 3.0
- 4th International Cloud Computing Conference & Expo Starts Today
- Deputy CIO of the CIA to Keynote 1st Annual GovIT Expo
- Publishing Synergy: Blog, Twitter and Ulitzer
- Cloud Computing Expo: Exclusive Q&A with Yahoo! SVP Cloud Computing
- Performance Tuning Essentials for Java
- Cloud Expo New York Call for Papers Deadline December 15
- IBM Hardware Chief, Intel VC Exec Arrested in Insider Trading Scam
- Oracle-Sun: IBM Reportedly Behind Delay
- Citrix Aims To Cripple VMware’s Cloud Designs
- Cloud Computing Can Revitalize Your Career as Software Developer
- Oracle Trashes HP Relationship for Sun
- Open Source Mobile Cloud Sync and Push Email
- After Ubuntu, Windows Looks Increasingly Bad, Increasingly Archaic, Increasingly Unfriendly
- SCO CEO Posts Open Letter to the Open Source Community
- Simula Labs Launches Hosted Delivery Platform To Enable Enterprise Open Source Adoption
- Where Are RIA Technologies Headed in 2008?
- Source Claims SCO Will Sue Google
- How Open Is "Open"? – Industry Luminaries Join the Debate
- Latest SCO News is Plain Weird
- IBM Tells SCO Court It Can't Find AIX-on-Power Code
- SCO Claims Linux Lifted ELF
- Flashback: Investing in 'Professional Open Source' - Exclusive 2004 Interview with David Skok, Matrix Partners
- HP Starts Pushing Desktop Linux
- Linux Business Week Exclusive: Linux Kernel To Be Re-Written To Counter Microsoft FUD





































