Apache Camel is the most commonly used application versatile open-source integration framework that easily integrates various systems producing or consuming data. So, I came up with this comprehensive Apache Camel Tutorial to briefly understand Apache Camel, EIPs, DSLs, etc.
These days, Data sharing between companies has increased enormously. Numerous integration of applications has increased as well. The user interface uses various technologies, data formats, and protocols. Yet, integrating such applications is modeled in a customized way, concerning efficiency and support by automatic tests.
For such standardized integration, Enterprise Integration Patterns (EIP) are used to document, implement, and define integration issues. Apache Camel came into existence to implement EIPs and provide customized, domain-specific language (DSL) to integrate applications easily.
In this Apache Camel Tutorial, I will be discussing the following topics: |
Apache Camel is an open-source integration framework depending on Enterprise Integration Patterns. It allows users to define mediation rules and routing in several specific languages, such as Java-based Spring, Blueprint XML, or Fluent API configuration files.
Apache Camel executes EIPs and provides a standardized, internal Domain-specific language (DSL) to integrate applications. Hence, the framework can be deployed with several standalone Java applications and servers such as Tomcat, Wildfly, or fully-fledged enterprise service.
The features of Apache Camel are as follows:
Camel offers an extensive library of more than 80 components, and these components allow Camel to connect with transports, data formats, and use APIs.
It has a modular architecture that enables the component to load into Camel.
Camel supports the POJO model and allows users to plugin Javabeans at several points.
It supports pluggable languages to create DSL programs and supports languages such as Python, SQL, XQuery, JavaScript, Ruby, PHP, Groovy, XPath, etc.
It makes testing of asynchronous and distributed systems using messaging.
Camel uses an easy and intuitive URI configuration to configure endpoints directly in routes.
It has an in-built type-converter mechanism that transfers more than 150 converters. So, there is no need to configure the type-converter from byte arrays.
It provides a Test kit that makes it easy to test the camel applications. The kit contains test-specific components that can help to test the real endpoints.
Do you want to become an Apache Camel Developer and build your career in this domain? Then enroll in "Apache Camel Training" this course will help you to achieve excellence in this domain. |
The Apache Camel architecture includes three main functions as Components, Processor, Integration Engine, and Router. The Camel core includes 13 essential components and 80+ components of minor components. It helps in maintaining low dependency where it can be deployed.
The components offer an Endpoint interface to the eternal world. The Processor is used to mediate and manipulate messages between Endpoints.
Processor and Endpoints are wired with each other in the Integration Engine and router using DSLs. EIPs are executed in this module. When wiring, use the filters to filter messages depending on user requirements.
Apache Camel includes various in-built components. The following are the few important components of Camel core.
bean: beanName
Control Bus: The Control Bus from the EIP patterns allows the integration system to be monitored and managed within the framework. It offers easy management of Camel applications depending on the Control Bus EIP pattern.
controlbus: command
Where command can be any string to identify the type of command to use.
Data Format: The Data format component enables the use of Data Format as a Camel component.
dataformat: name: (marshal/unmarshal)
Where name is the name of the Data Format. It is used for configuring the Data Format in use.
Direct: The Direct component offers the consumer's synchronous invocation in a JVM when the producer sends a message in return.
This endpoint can be used to connect existing routes in the same camel context.
direct: someName
Where someName can be any string to identify the endpoint uniquely.
File: The File component provides access to file systems, allowing files to be processed by any other Camel Components or messages from other components to be saved to disk.
file:directoryName or file://directoryName
Where directoryName represents the underlying file directory.
Log: The Log component logs message transfers to the basic logging method that allows users to configure logging through the following:
Log4j
Log back
Java Util Logging
log: loggingCategory
Where the logging category is the name of the logging category to use.
REST API: A REST API component is used for providing Swagger API of the REST services, which has been defined using the rest-DSL in Camel.
Its endpoint is configured by URI syntax:
rest-api :path/contextIdPattern
Scheduler: The Scheduler component helps to generate message exchanges when a scheduler requires. It is as same as the Timer component, but it offers more functions in terms of scheduling. Also, this component uses JDK ScheduledExecutorService. Then the timer uses a JDK.
scheduler: name
Where name is the name of the scheduler that is created and shared over the endpoints.
Validator: The Validation component executes XML validation of the message body by JAXP Validation API, and depending on any supported XML languages, that defaults to the XML Schema.
validator: someLocalOrRemoteResource
Where someLocalOrRemoteResource is URL to the local resource on the classpath or to a remote resource on the file system that includes the XSD to validate.
XSLT: The XSLT component allows you to process a message using an XSLT template. This can be ideal when using Templating to generate a response for requests.
xslt:templateName
The URI format includes templateName that can be
The complete URL of the remote template.
The classpath-local URI of the template to invoke.
Enterprise Integration Patterns (EIP)s can be used to break the integration issues into smaller pieces and create them using standardized graphics. Even a non-technical person can understand the models easily. With the help of EIPs, Apache Camel reduces the gap between implementation and modeling. There is a relationship between Apache Camels EIP and the DSL models.
CamelContext offers access to all other services in Apache Camel. The CamelContext is the Apache Camels runtime system that connects various concepts such as endpoints, components, or routes.
The Registry module is a JNDI registry that holds the name of several Java beans by default in the application. The Type converters include several loaded type converters that convert the input from one format to another. The Components consist of the components used by the application. Data formats include loaded data formats.
The default CamelContext offers a concrete implementation of CamelContext.The runtime system includes JVM, OSGi container, JEE application server (e.g., IBM WebSphere AS), and a web container (e.g., Tomcat).
Domain-Specific Languages (DSL)s enables the realization of the complex project using a high abstraction level. Camel offers several DSL models. Scala, Java, and Groovy and use object-oriented concepts to provide a particular method for EIPs. Also, Spring XML DSL uses XML configuration and is built on the Spring framework.
Java DSL has IDE support. Scala and Groovy DSLs are as same as Java DSL. Besides, they provide features of JVM languages such as closures or concise code. Spring XML DSL requires XML, and it gives a powerful Spring-based dependency injection technique and abstractions to basic configurations (such as JMS or JDBC connections).
Even any combination can be made. Many developers use Spring XML to configure while routes are noticed in Groovy, Java, or Scala.
To build a Camel project, do the following steps:
To create a new project, specify the following.
Select the default location of the project or specify the directory.
Open pom.xml to add the dependencies.
Note: Make sure to use a minimum number of dependencies of our application. As we use more components from the library, it is required to add the respective dependencies in the .XML file.
Write the filtering and routing code in Java DSL. Create a new Java class known as DistributeOrderDSL.
We create CamelContext by a default implementation offered as DefaultCamelContext class.
Now, add a route by creating an unknown RouteBuilder.
Override the configure method to add a route from the direct URI DisributeOrderDSL to the system console.
Start the context
Add the code for creating the direct URI- DistributeOrderDSL.
Now, start the processing.
Java DSL code is completed, add the order.xml file to the project, and it is good to go for testing.
Run the application; you will get the following output.
Ensure that only orders are listed. If you want to store these results in a local file, then comment on the stream. out and uncomment the configure method by the following line.
This is how we create a new Maven project.
<h3id="new-pjoect-using-springs" dir="ltr">How to create a new project using Springs?
We recreate the application using Spring. To create Camel routing in XML instead of DSL, do the following steps.
Create a new project and specify the following.
Select the default location or specify the directory.
With the core dependencies used in the earlier application, add a few more dependencies to use Spring. Open pom.xml to add more dependencies.
Create a new Java class known as DistributeOrderXML and add the code given below.
We create an example of ApplicationContext that is the central interface in the Spring application. Now specify the XML file name that includes routing and filtering details.
Create CamelContext defining the ApplicationContext created.
Start the CamelContext using the start method. We define the Endpoint for loading the order.xml file and start processing.
Add a new XML file to the project and call for SpringRouteContext.xml. Use the code given below.
Here, we define the XPath query. Note that we now select all orders.
The output Endpoints are numerous. The first endpoint defines the order folder, and the second endpoint represents the console.
Now, run the application.
After running the application, you will get the following output on the screen.
Check the order folder in the path specified. You will find the newly created file that includes the above XML code.
Apache Camel offers a framework to implement EIPs to make it easy for integrating the projects. It also supports coding in Domain-specific Languages (DSL) and even the XML file. Camel supports all the requirements used in Enterprise projects such as scalability, monitoring, transactions, and error handling. The most important advantage is that the same syntax and concepts can be used anytime, even for automatic tests, whatever the technologies have to be integrated.
Our work-support plans provide precise options as per your project tasks. Whether you are a newbie or an experienced professional seeking assistance in completing project tasks, we are here with the following plans to meet your custom needs:
Name | Dates | |
---|---|---|
Apache Nifi Training | Nov 23 to Dec 08 | View Details |
Apache Nifi Training | Nov 26 to Dec 11 | View Details |
Apache Nifi Training | Nov 30 to Dec 15 | View Details |
Apache Nifi Training | Dec 03 to Dec 18 | View Details |
Keerthana Jonnalagadda working as a Content Writer at Mindmajix Technologies Inc. She writes on emerging IT technology-related topics and likes to share good quality content through her writings. You can reach her through LinkedIn.