Apache Camel + Spring + ActiveMQ + JBoss Fuse | JavaInUse




JBoss Fuse Tutorial - Apache Camel + Spring + ActiveMQ + JBoss Fuse



Overview

We will implement a simple Apache camel integration project with Apache Camel using Spring DSL and deploy it on Red Hat JBoss Fuse.

Apache Camel - Table of Contents

File Transfer Using Java DSL Apache Camel Apache Camel Java DSL + Spring Integration Hello World Example Apache Camel Exception Handling Using Simple Example Apache Camel Redelivery policy using example Integrate Apache Camel and ActiveMQ EIP patterns using Apache Camel Apache Camel Tutorial- Integrate Spring Boot+ Apache Camel Apache Camel Tutorial- Integrate with MySQL DB using SQL query Apache Camel EIP - Splitter and Aggregator pattern Apache Camel Unit Testing Apache Camel + Spring + Quartz Hello World Example Camel application deployment on JBoss Fuse Apache Camel + Spring + ActiveMQ + JBoss Fuse Apache Camel + Apache CXF SOAP Webservices Apache Camel + JAX-RS REST Webservice Apache Camel + CXFRS REST Webservice Apache Camel Routing Slip EIP Pattern Apache Camel Dynamic Router Pattern Apache Camel Load Balancer EIP Pattern Apache Camel Interceptors Apache Camel + Kafka Hello World Example Apache Camel - Marshalling/Unmarshalling XML/JSON Data Example

Video

This tutorial is explained in the below Youtube Video.

Lets Begin

The camel configuration file is to be created in src->main->resources->META-INF->spring. This is the default path where camel looks for the config files.
We will create Eclipse Maven project as follows-

The pom file will be as follows-
	<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<groupId>com.test</groupId>
	<artifactId>TestActiveMQ</artifactId>
	<version>0.0.1-SNAPSHOT</version>

	<packaging>bundle</packaging>
	<dependencies>
		<dependency>
			<groupId>org.apache.camel</groupId>
			<artifactId>camel-core</artifactId>
			<version>2.8.0</version>
		</dependency>

		<dependency>
			<groupId>org.apache.camel</groupId>
			<artifactId>camel-spring</artifactId>
			<version>2.8.0</version>
		</dependency>

	</dependencies>
	<build>
		<plugins>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-compiler-plugin</artifactId>
				<version>3.1</version>
			</plugin>
			<plugin>
				<groupId>org.apache.felix</groupId>
				<artifactId>maven-bundle-plugin</artifactId>
				<extensions>true</extensions>
				<version>2.4.0</version>
			</plugin>

		</plugins>
	</build>
</project>

The config file applicationContext.xml will be as follows. We have created a camel context. Inside the context we have written a camel route. This route logs any message that is sent to our queue.
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:camel="http://camel.apache.org/schema/spring"
	xmlns:osgi="http://www.springframework.org/schema/osgi" xmlns:cxf="http://camel.apache.org/schema/cxf"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/osgi http://www.springframework.org/schema/osgi/spring-osgi.xsd http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd http://camel.apache.org/schema/cxf http://camel.apache.org/schema/cxf/camel-cxf-2.8.3.xsd">

	<camelContext id="camelId" xmlns="http://camel.apache.org/schema/spring">
		<camel:route>
			<camel:from uri="amq:queue:queue1" />
			<camel:log message="Message returned from the queue is " />
		</camel:route>
	</camelContext>
</beans>
We also need a file for configuring the ActiveMQ.
 <?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:camel="http://camel.apache.org/schema/spring"
	xmlns:osgi="http://www.springframework.org/schema/osgi" xmlns:cxf="http://camel.apache.org/schema/cxf"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd  http://www.springframework.org/schema/osgi http://www.springframework.org/schema/osgi/spring-osgi.xsd       http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd       http://camel.apache.org/schema/cxf http://camel.apache.org/schema/cxf/camel-cxf-2.8.3.xsd">


	<bean class="org.apache.activemq.camel.component.ActiveMQComponent"
		id="amq">
		<property name="connectionFactory" ref="singleCF" />
		<property name="useSingleConnection" value="true" />
		<property name="usePooledConnection" value="false" />
		<property name="preserveMessageQos" value="true" />
	</bean>

	<bean class="org.springframework.jms.connection.SingleConnectionFactory"
		id="singleCF">
		<property name="targetConnectionFactory" ref="AMQCF" />
	</bean>

	<bean class="org.apache.activemq.ActiveMQConnectionFactory" id="AMQCF">
		<property name="userName" value="admin" />
		<property name="password" value="admin" />
		<property name="brokerURL" value="tcp://localhost:61616" />
	</bean>
</beans>
 
 

That is the only code required. Now run the following Maven command
-clean:install
Next go to fuse.bat and start it by double clicking on it.
To run the bundle that is generated in .m2 repo type the following command
-install mvn:com.javainuse/test-activemq/0.0.1-SNAPSHOT..
This gives us a bundle-id. Next run the start bundle-id command.

Our camel-file-transfer application is now up and running.
Go to JBoss Fuse url- localhost:8181.
Check the activemq queue as follows-

We will see the Queue queue1 created. Send any message to the queue and it will be get logged. This can be checked in the fuse.log file.

Download Source Code

Download it - Apache Camel integration with ActiveMQ

See Also

Spring Boot Hello World Application- Create simple controller and jsp view using Maven Spring Boot Tutorial-Spring Data JPA Spring Boot + Simple Security Configuration Pagination using Spring Boot Simple Example Spring Boot + ActiveMQ Hello world Example Spring Boot + Swagger Example Hello World Example Spring Boot + Swagger- Understanding the various Swagger Annotations Spring Boot Main Menu Spring Boot Interview Questions