Welcome!

Microservices Expo Authors: Liz McMillan, Elizabeth White, Pat Romanski, Yeshim Deniz, Zakia Bouachraoui

Related Topics: Microservices Expo, Java IoT

Microservices Expo: Article

SOA Made Easy: Open Source Apache Camel

A POJO-based implementation of the Enterprise Integration Patterns

Next you must start the Camel context. If you're using Spring (http://cwiki.apache.org/confluence/display/CAMEL/Spring) to configure the Camel context this is done automatically for you; although if you're using a pure Java approach then you just need to call the start() method:

camelContext.start();

This will start all of the configured routing rules.

So after starting the CamelContext (http://cwiki.apache.org/confluence/display/CAMEL/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 (http://cwiki.apache.org/confluence/display/CAMEL/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 (http://activemq.apache.org/camel/maven/camel-core/apidocs/org/apache/camel/CamelTemplate.html) we send objects (in this case text) into the CamelContext (http://cwiki.apache.org/confluence/display/CAMEL/CamelContext) to the Component test-jms:queue:test.queue. These text objects will be converted automatically (http://cwiki.apache.org/confluence/display/CAMEL/Type+Converter) into JMS Messages and posted to a JMS queue named test.queue. When we set up the route (http://cwiki.apache.org/confluence/display/CAMEL/Routes), we configured the FileComponent (http://cwiki.apache.org/confluence/display/CAMEL/File) to listen of the test.queue.

The FileComponent file (http://cwiki.apache.org/confluence/display/CAMEL/File) 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 (http://cwiki.apache.org/confluence/display/CAMEL/Routes) to take notifications from the FileComponent (http://cwiki.apache.org/confluence/display/CAMEL/File) 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 gener-ated files in the target/outputFiles directory, which are the transformed messages read from the JMS queue.

Code Walk Through
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/

More Stories By Robert Davies

Rob Davies is chief technology officer at FuseSource. One of the original members of the team, he co-founded LogicBlaze which was purchased by IONA and is now FuseSource. Prior to working for Logicblaze, he was a founder and the CTO of SpiritSoft which was purchased by Sun Microsystems. Rob has over 20 years experience of developing high performance distributed enterprise systems and products for telcos and finance, and is best known for his work at the Apache Software Foundation where he co-founded the ServiceMix, ActiveMQ, and Camel projects. He is now the PMC chair of ServiceMix and continues to be an active committer on all three projects. You can read his blog, On Open Source Integration, or follow him on twitter.

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.

Comments (0)

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.


Microservices Articles
CloudEXPO New York 2018, colocated with DXWorldEXPO New York 2018 will be held November 11-13, 2018, in New York City and will bring together Cloud Computing, FinTech and Blockchain, Digital Transformation, Big Data, Internet of Things, DevOps, AI, Machine Learning and WebRTC to one location.
Most DevOps journeys involve several phases of maturity. Research shows that the inflection point where organizations begin to see maximum value is when they implement tight integration deploying their code to their infrastructure. Success at this level is the last barrier to at-will deployment. Storage, for instance, is more capable than where we read and write data. In his session at @DevOpsSummit at 20th Cloud Expo, Josh Atwell, a Developer Advocate for NetApp, will discuss the role and value...
SYS-CON Events announced today that DatacenterDynamics has been named “Media Sponsor” of SYS-CON's 18th International Cloud Expo, which will take place on June 7–9, 2016, at the Javits Center in New York City, NY. DatacenterDynamics is a brand of DCD Group, a global B2B media and publishing company that develops products to help senior professionals in the world's most ICT dependent organizations make risk-based infrastructure and capacity decisions.
"We do one of the best file systems in the world. We learned how to deal with Big Data many years ago and we implemented this knowledge into our software," explained Jakub Ratajczak, Business Development Manager at MooseFS, in this SYS-CON.tv interview at 20th Cloud Expo, held June 6-8, 2017, at the Javits Center in New York City, NY.
DevOpsSummit New York 2018, colocated with CloudEXPO | DXWorldEXPO New York 2018 will be held November 11-13, 2018, in New York City. Digital Transformation (DX) is a major focus with the introduction of DXWorldEXPO within the program. Successful transformation requires a laser focus on being data-driven and on using all the tools available that enable transformation if they plan to survive over the long term.
Enterprise architects are increasingly adopting multi-cloud strategies as they seek to utilize existing data center assets, leverage the advantages of cloud computing and avoid cloud vendor lock-in. This requires a globally aware traffic management strategy that can monitor infrastructure health across data centers and end-user experience globally, while responding to control changes and system specification at the speed of today’s DevOps teams. In his session at 20th Cloud Expo, Josh Gray, Chie...
Containers and Kubernetes allow for code portability across on-premise VMs, bare metal, or multiple cloud provider environments. Yet, despite this portability promise, developers may include configuration and application definitions that constrain or even eliminate application portability. In this session we'll describe best practices for "configuration as code" in a Kubernetes environment. We will demonstrate how a properly constructed containerized app can be deployed to both Amazon and Azure ...
Modern software design has fundamentally changed how we manage applications, causing many to turn to containers as the new virtual machine for resource management. As container adoption grows beyond stateless applications to stateful workloads, the need for persistent storage is foundational - something customers routinely cite as a top pain point. In his session at @DevOpsSummit at 21st Cloud Expo, Bill Borsari, Head of Systems Engineering at Datera, explored how organizations can reap the bene...
In his session at 20th Cloud Expo, Scott Davis, CTO of Embotics, discussed how automation can provide the dynamic management required to cost-effectively deliver microservices and container solutions at scale. He also discussed how flexible automation is the key to effectively bridging and seamlessly coordinating both IT and developer needs for component orchestration across disparate clouds – an increasingly important requirement at today’s multi-cloud enterprise.
In his session at 20th Cloud Expo, Mike Johnston, an infrastructure engineer at Supergiant.io, discussed how to use Kubernetes to set up a SaaS infrastructure for your business. Mike Johnston is an infrastructure engineer at Supergiant.io with over 12 years of experience designing, deploying, and maintaining server and workstation infrastructure at all scales. He has experience with brick and mortar data centers as well as cloud providers like Digital Ocean, Amazon Web Services, and Rackspace. H...