Introduction to the Apache-Camel
This is my first blog in the camel blog series. The inspiration to write a blog about camel came after going through the painful process of learning camel from the incomplete apache documentation with little real case examples. Our team was implementing a service orchestration layer on top of camel for one of the clients in Atlanta. The camel community documentation was not simple enough for our developers. As a team our prior experience was on Service-mix and Spring Integration and all of us were completely new to the camel. In this Blog series I have kept the basic operations simple as possible. As we progress I will be covering topics like – simple operations using Simple, Http Headers, Cookie management in Http component, custom Java beans and camel integration, Route performance optimization, and dynamic scripting using Groovy.
You will need the below software’s setup before getting your hands dirty writing camel routes.
- Maven (version 3 or above)
- Apache Camel (version 2.8.3 or above)
- A Good IDE with maven support (preferably eclipse with maven plugin)
- An http client (I use Rest-Client plugin for Mozilla Firefox)
What is Apache-Camel, is it another web service middle-ware?
Apache Camel is a very interesting project. It’s not new and has been around for some time. At the time of this write up it is at version 2.8.3. I came across the camel project in one of my client location in Atlanta, GA. It’s unbelievably flexible. And just like anything that offers flexibility this one also can be misused if used without proper guidance and design. Prior experience and knowledge on individual components and protocols used in your service existing enterprise services are more important than camel expertise. Camel wires and glues the components you choose, to achieve the desired logical flow. But by itself camel is pretty lame and not the magical wizard of integration.
From a developer perspective camel is a highly flexible routing engine with support for almost all the available standard components, pattern’s, languages, libraries, protocols etc. that are common in the software service industry. Camel is backed by maven for build and dependency management.
Camel is built on top of spring. The smallest logical unit of a camel project is called a route. Each route should have at least one ‘from’ endpoint and a ‘to’ endpoint. There are several ways to write a route – Java, Groovy, Scala, Spring DSL etc are some of the mechanism to write deployable routes. We used the camel Spring DSL to wire and glue all the service end points in our infrastructure for a quick demo.
Features of Apache-Camel
- It supports and heavily relies on EIP (Enterprise Integration Patterns) and has built in adapters for achieving these patterns.
- It supports a dozen programming languages and scripts -Java, Groovy, Scala, Simple, Python, Ruby, Java script, Php, Beanshell, SQL, Spring DSL, XPath expressions.
- It has connector components for – http, async http, ftp, sftp, ldap, smtp, tcp, xmpp, stream, dns, sip, udp.
- It has in-built parsers for – xml, json, csv, smooks.
- It supports other services and transport frameworks like – CXF, Spring-WS, Mina, Servicemix, JBI, Amazon Simple Que (AWS-SQS), etc.
- It provides messaging support for – Active-MQ, JMS, AMQP, Apple Push Notifications, Amazon Simple Notification Service (AWS-SNS), Kestrel, JT-400 (Component for interacting Queues on AS/400).
- It has built in components for – Cache (EH-Cache is the default implementation), Bean Validation, Bean Bindings, Crypto (Using Java cryptographic extension), File, Exec (Execute System Commands), Vm (asynchronous call to another endpoint in same jvm) etc.
- Camel provides almost all the standard front controllers for serving as starting endpoints (‘from’) – Servlet, Jetty, Comet, EJB, Restlet
- Camel supports hosting and clustering infrastructures of all major enterprise application engines – Gtask (Google App Engine), Nagios etc.
- Camel supports templates and transformation’s on data using – Velocity, XSLT, Free Marker etc.
Benefits of using camel based middle-ware compared to a legacy service middle-ware
Production Ready in hours compared to months - take it from me, we saved tons of time by utilizing dynamic scripting and routes on top of camel to rapidly develop a production quality service computing grid. To develop a service middle ware with scalability, high availability and flexibility to accommodate last minute changes we would have taken ages with a traditional – ‘compiled code environment’. Groovy was more productive within routes compared to its typical usage within grails app.
No Boiler Plate code – Camel solves most of our coding redundancy by providing constructs and components to solve everyday programming needs. So you do not write those repeated spring/java controller IOC code/annotations for wiring a couple of services.
Reduces Security loop holes in exposing services over internet – Exposing your service back ends over public internet for internatinal clients for testing can leave a security hole in your infrastructure. In our case it was always safe to keep the actual service proxied by camel route without affecting performance, and the changes could be reflected in minutes. Thus our actual web services became lean and thin without the heavy weight security modules from EJB containers.
Standard Components and modules – In many cases we have seen a lot of time is invested on figuring out the best library/component to achieve a particular functionality in a Java/J2EE project. With camel all the standard components are already pre-packed and supported out of the box, you add it to the pom file and it’s there ready to be used within your route.
Reuse Existing Knowledge base – Camel is one of the few service middle wares that supports almost all the leading scripting languages including – PHP, Python, Js, Ruby, Groovy, Bean Shell, OGNL, Simple, EL, Xpath, XQuery, Mvel, JoSQL etc. Camel supports any JSR 223 scripting language using DSL methods. What does this mean – Good news, your company/organization can use the existing in house expertise in leveraging camels offering.
Disclaimer
The opinions expressed here are my personal opinions. contant published here is not read or approved in advance by EMC and does not reflect the views or opinions of EMC