Red Hat JBoss Fuse ESB + Apache Camel + MySQL + OSGI Blueprint DSL

In this blog, we will learn Apache Camel integration with MySQL database with OSGI Blueprint DSL.

Application Architecture Overview

This example contains step by step guide for MySQL database integration. Here we will learn marshalling and unmarshalling in details.

How to create/expose a Queue (com.the.basic.tech.info.inputQueue) for publishing the xml message.

How to create xsd schema file.

How to generate jaxData from xsd schema.

How to unmarshal xml to Java POJO classes.

How to marshal Java POJO to JSON objects.

How to store xml and json payloads into MYSQL database using SQL Query.

How to implement password jasypt encryption and decryption in fuse and apache camel.

How to use XPath expressions and predicates for extracting attributes value from XML payload.

How to create database schema for storing records in MySQL database.

How to implement sql component for inserting records in MySQL database.

How to create the features.xml and add into karaf container using features:addurl command.

How to build & install bundle in Red hat jboss fuse esb.

Application Structure

High level Project structure would be looked like as below.

Apache Camel MySQL Application Architecture

Maven File : pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
	<modelVersion>4.0.0</modelVersion>
	<groupId>com.the.basic.tech.info</groupId>
	<artifactId>camel-blueprint-mysql</artifactId>
	<version>1.0.0-SNAPSHOT</version>
	<packaging>bundle</packaging>
	<name>Camel Blueprint MySQL Quickstart</name>
	<description>Camel Blueprint MySQL Example</description>
	<licenses>
		<license>
			<name>Apache License, Version 2.0</name>
			<url>http://www.apache.org/licenses/LICENSE-2.0.html</url>
			<distribution>repo</distribution>
		</license>
	</licenses>
	<properties>
		<camel.version>2.17.0.redhat-630187</camel.version>
		<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
		<version.maven-bundle-plugin>3.2.0</version.maven-bundle-plugin>
		<jboss.fuse.bom.version>6.3.0.redhat-187</jboss.fuse.bom.version>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
	</properties>
	<dependencyManagement>
		<dependencies>
			<dependency>
				<groupId>org.jboss.fuse.bom</groupId>
				<artifactId>jboss-fuse-parent</artifactId>
				<version>${jboss.fuse.bom.version}</version>
				<type>pom</type>
				<scope>import</scope>
			</dependency>
		</dependencies>
	</dependencyManagement>
	<dependencies>
		<dependency>
			<groupId>org.apache.camel</groupId>
			<artifactId>camel-core</artifactId>
		</dependency>
		<dependency>
			<groupId>org.apache.camel</groupId>
			<artifactId>camel-jms</artifactId>
		</dependency>
		<dependency>
			<groupId>org.apache.camel</groupId>
			<artifactId>camel-jaxb</artifactId>
		</dependency>
		<dependency>
			<groupId>org.apache.camel</groupId>
			<artifactId>camel-jackson</artifactId>
		</dependency>
		<dependency>
			<groupId>org.apache.camel</groupId>
			<artifactId>camel-jacksonxml</artifactId>
		</dependency>		
		<dependency>
			<groupId>org.apache.camel</groupId>
			<artifactId>camel-blueprint</artifactId>
		</dependency>
		<dependency>
			<groupId>org.apache.activemq</groupId>
			<artifactId>activemq-client</artifactId>
		</dependency>
		<dependency>
			<groupId>org.apache.activemq</groupId>
			<artifactId>activemq-camel</artifactId>
		</dependency>
		<dependency>
			<groupId>org.apache.activemq</groupId>
			<artifactId>activemq-pool</artifactId>
		</dependency>
		<dependency>
			<groupId>org.apache.activemq</groupId>
			<artifactId>activemq-broker</artifactId>
		</dependency>
		<dependency>
			<groupId>org.apache.activemq</groupId>
			<artifactId>activemq-kahadb-store</artifactId>
		</dependency>
		<dependency>
			<groupId>mysql</groupId>
			<artifactId>mysql-connector-java</artifactId>
			<version>8.0.22</version>
		</dependency>
		<dependency>
			<groupId>commons-dbcp</groupId>
			<artifactId>commons-dbcp</artifactId>
		</dependency>
		<dependency>
			<groupId>commons-pool</groupId>
			<artifactId>commons-pool</artifactId>
		</dependency>
		<dependency>
			<groupId>org.apache.camel</groupId>
			<artifactId>camel-sql</artifactId>
		</dependency>
		<dependency>
			<groupId>org.slf4j</groupId>
			<artifactId>slf4j-api</artifactId>
		</dependency>
		<dependency>
			<groupId>org.slf4j</groupId>
			<artifactId>slf4j-log4j12</artifactId>
		</dependency>
		<dependency>
			<groupId>log4j</groupId>
			<artifactId>log4j</artifactId>
		</dependency>
		<dependency>
			<groupId>org.apache.camel</groupId>
			<artifactId>camel-test-blueprint</artifactId>
			<scope>test</scope>
			<exclusions>
				<exclusion>
					<artifactId>org.apache.felix.fileinstall</artifactId>
					<groupId>org.apache.felix</groupId>
				</exclusion>
			</exclusions>
		</dependency>
	</dependencies>
	<repositories>
		<repository>
			<releases>
				<enabled>true</enabled>
				<updatePolicy>never</updatePolicy>
			</releases>
			<snapshots>
				<enabled>false</enabled>
			</snapshots>
			<id>fuse-public-repository</id>
			<name>FuseSource Community Release Repository</name>
			<url>https://repo.fusesource.com/nexus/content/groups/public</url>
		</repository>
		<repository>
			<releases>
				<enabled>true</enabled>
				<updatePolicy>never</updatePolicy>
			</releases>
			<snapshots>
				<enabled>false</enabled>
			</snapshots>
			<id>red-hat-ga-repository</id>
			<name>Red Hat GA Repository</name>
			<url>https://maven.repository.redhat.com/ga</url>
		</repository>
	</repositories>
	<pluginRepositories>
		<pluginRepository>
			<releases>
				<enabled>true</enabled>
				<updatePolicy>never</updatePolicy>
			</releases>
			<snapshots>
				<enabled>false</enabled>
			</snapshots>
			<id>fuse-public-repository</id>
			<name>FuseSource Community Release Repository</name>
			<url>https://repo.fusesource.com/nexus/content/groups/public</url>
		</pluginRepository>
		<pluginRepository>
			<releases>
				<enabled>true</enabled>
				<updatePolicy>never</updatePolicy>
			</releases>
			<snapshots>
				<enabled>false</enabled>
			</snapshots>
			<id>red-hat-ga-repository</id>
			<name>Red Hat GA Repository</name>
			<url>https://maven.repository.redhat.com/ga</url>
		</pluginRepository>
	</pluginRepositories>
	<build>
		<defaultGoal>install</defaultGoal>
		<plugins>
			<plugin>
				<groupId>org.apache.felix</groupId>
				<artifactId>maven-bundle-plugin</artifactId>
				<version>${version.maven-bundle-plugin}</version>
				<extensions>true</extensions>
				<configuration>
					<instructions>
						<Bundle-SymbolicName>fuse-apache-camel-mysql-integration</Bundle-SymbolicName>
						<Bundle-Name>Camel Blueprint MySQL Example [fuse-apache-camel-mysql-integration]</Bundle-Name>
						<Import-Package>							
							*,org.jasypt.encryption.pbe
						</Import-Package>
						<DynamicImport-Package>
							*
						</DynamicImport-Package>
					</instructions>
				</configuration>
			</plugin>
			<plugin>
				<artifactId>maven-compiler-plugin</artifactId>
				<version>3.5.1</version>
				<configuration>
					<source>1.8</source>
					<target>1.8</target>
				</configuration>
			</plugin>
			<plugin>
				<artifactId>maven-resources-plugin</artifactId>
				<version>3.0.1</version>
				<configuration>
					<encoding>UTF-8</encoding>
				</configuration>
			</plugin>
			<plugin>
				<groupId>org.apache.camel</groupId>
				<artifactId>camel-maven-plugin</artifactId>
				<version>${camel.version}</version>
				<configuration>
					<useBlueprint>true</useBlueprint>
				</configuration>
			</plugin>
		</plugins>
	</build>
</project>

How to create/expose a Queue (com.the.basic.tech.info.inputQueue) for publishing the xml message.

We need to add below beans for configuring activemq broker for publishing a message to the Queue.

<bean class="org.apache.activemq.ActiveMQConnectionFactory" id="activemq-connection-factory">
        <property name="brokerURL" value="${broker.url}"/>
        <property name="userName" value="${broker.username}"/>
        <property name="password" value="$[broker.password]"/>
    </bean>
    <bean class="org.apache.activemq.pool.PooledConnectionFactory" destroy-method="stop" id="pooledConnectionFactory" init-method="start">
        <property name="maxConnections" value="1"/>
        <property name="blockIfSessionPoolIsFull" value="true"/>
        <property name="createConnectionOnStartup" value="true"/>
        <property name="connectionFactory" ref="activemq-connection-factory"/>
    </bean>
    <bean class="org.apache.camel.component.jms.JmsConfiguration" id="jmsConfiguration">
        <property name="connectionFactory" ref="pooledConnectionFactory"/>
        <property name="concurrentConsumers" value="10"/>
        <property name="maxConcurrentConsumers" value="60"/>
    </bean>
    <bean class="org.apache.activemq.camel.component.ActiveMQComponent" id="activemq">
        <property name="configuration" ref="jmsConfiguration"/>
 </bean>

How to configure a datasource for sql component

Following bean we need to add for configuring datasource for sql component.

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
  <property name="driverClassName" value="com.mysql.cj.jdbc.Driver" />
  <property name="url" value="${db.url}" />
  <property name="username" value="${db.username}" />
   <property name="password" value="$[db.password]" />
</bean>

Application/Bundle configuration

Two files are added for configuring the application properties.

camel.blueprint.mysql.bundle.cfg contains broker and mysql configurations and camel.blueprint.mysql.bundle.enc.cfg contains encrypted password for broker and mysql.

camel.blueprint.mysql.bundle.cfg

#ActiveMQ Broker

broker.url=tcp://localhost:61616
broker.username=admin

#Database
db.url=jdbc:mysql://localhost:3306/bootdb?useUnicode=true;characterEncoding=UTF-8;zeroDateTimeBehavior=convertToNull;serverTimezone=GMT
db.username=root

#Database Query
#CREATE TABLE employees (empId VARCHAR(10) NOT NULL, empName VARCHAR(100) NOT NULL, xmlPayload VARCHAR(1000), jsonPayload VARCHAR(1000), created timestamp, correlationid VARCHAR(200));
sql.insertEmployee=INSERT INTO employees(EmpId, EmpName, XmlPayload, JsonPayload, Created, Correlationid) VALUES (:#EmpId, :#EmpName, :#XmlPayload, :#JsonPayload, CURRENT_TIMESTAMP, :#Correlationid)
sql.getAllEmployees=select * from employees

camel.blueprint.mysql.bundle.enc.cfg

#ActiveMQ Broker Encrypted
broker.password=admin
db.password=admin

Note: We can encrypt above broker and db password with Jasypt online tool and replace here. Also, we can add encryption key in windows env variable e.g. ENCRYPTION_PASSWORD=<Jasypt_key>

For supporting Jasypt encrypted properties we need to add below configuration in our camel-beans.xml file

<cm:property-placeholder id="camel.blueprint.mysql.bundle" persistent-id="camel.blueprint.mysql.bundle" update-strategy="reload"/>
    <cm:property-placeholder id="camel.blueprint.mysql.bundle.enc" persistent-id="camel.blueprint.mysql.bundle.enc" placeholder-prefix="$[" placeholder-suffix="]" update-strategy="reload"/>
    <enc:property-placeholder>
        <enc:encryptor class="org.jasypt.encryption.pbe.StandardPBEStringEncryptor ">
            <property name="config">
                <bean class="org.jasypt.encryption.pbe.config.EnvironmentStringPBEConfig">
                    <property name="algorithm" value="PBEWITHHMACSHA512ANDAES_256"/>
                    <property name="passwordEnvName" value="ENCRYPTION_PASSWORD"/>
                </bean>
            </property>
        </enc:encryptor>
    </enc:property-placeholder>

Complete camel-beans.xml file would be looked like as below.

<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" xmlns:camel="http://camel.apache.org/schema/blueprint" xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0" xmlns:enc="http://karaf.apache.org/xmlns/jasypt/v1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0 https://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd        http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint.xsd">
    <cm:property-placeholder id="camel.blueprint.mysql.bundle" persistent-id="camel.blueprint.mysql.bundle" update-strategy="reload"/>
    <cm:property-placeholder id="camel.blueprint.mysql.bundle.enc" persistent-id="camel.blueprint.mysql.bundle.enc" placeholder-prefix="$[" placeholder-suffix="]" update-strategy="reload"/>
    <enc:property-placeholder>
        <enc:encryptor class="org.jasypt.encryption.pbe.StandardPBEStringEncryptor ">
            <property name="config">
                <bean class="org.jasypt.encryption.pbe.config.EnvironmentStringPBEConfig">
                    <property name="algorithm" value="PBEWITHHMACSHA512ANDAES_256"/>
                    <property name="passwordEnvName" value="ENCRYPTION_PASSWORD"/>
                </bean>
            </property>
        </enc:encryptor>
    </enc:property-placeholder>
    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
		<property name="driverClassName" value="com.mysql.cj.jdbc.Driver" />
		<property name="url" value="${db.url}" />
		<property name="username" value="${db.username}" />
		<property name="password" value="$[db.password]" />
	</bean>

	<bean id="sqlComponent" class="org.apache.camel.component.sql.SqlComponent">
		<property name="dataSource" ref="dataSource" />
	</bean>

	<bean class="org.apache.activemq.ActiveMQConnectionFactory" id="activemq-connection-factory">
        <property name="brokerURL" value="${broker.url}"/>
        <property name="userName" value="${broker.username}"/>
        <property name="password" value="$[broker.password]"/>
    </bean>
    <bean class="org.apache.activemq.pool.PooledConnectionFactory" destroy-method="stop" id="pooledConnectionFactory" init-method="start">
        <property name="maxConnections" value="1"/>
        <property name="blockIfSessionPoolIsFull" value="true"/>
        <property name="createConnectionOnStartup" value="true"/>
        <property name="connectionFactory" ref="activemq-connection-factory"/>
    </bean>
    <bean class="org.apache.camel.component.jms.JmsConfiguration" id="jmsConfiguration">
        <property name="connectionFactory" ref="pooledConnectionFactory"/>
        <property name="concurrentConsumers" value="10"/>
        <property name="maxConcurrentConsumers" value="60"/>
    </bean>
    <bean class="org.apache.activemq.camel.component.ActiveMQComponent" id="activemq">
        <property name="configuration" ref="jmsConfiguration"/>
    </bean>
</blueprint>

Camel Route : camel-context.xml

Camel route file contains all the camel routes for integrations.

<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0 https://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd                            http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint.xsd">
	<camelContext id="fuse-apache-camel-mysql-integration-context" xmlns="http://camel.apache.org/schema/blueprint">
		<dataFormats>
			<jaxb contextPath="com.the.basic.tech.info.jaxb.beans" id="jaxData" />
			<json enableJaxbAnnotationModule="true" id="jack" library="Jackson" prettyPrint="true" unmarshalTypeName="com.the.basic.tech.info.beans.pojo.Employees" />
		</dataFormats>
		<onException>
			<exception>java.lang.Exception</exception>
			<handled>
				<constant>true</constant>
			</handled>
			<log message="Exception while processing Message. Preparing Error response. \n ${exception.stacktrace}" />
		</onException>
		<route id="inputQueue" streamCache="true">
			<from id="listenToIncomingMessage" uri="activemq:com.the.basic.tech.info.inputQueue" />
			<log id="logToIncomingMessage" message="Input Message Body :: ${body}" />
			<setHeader headerName="Correlationid" id="_setHeaderCorrelationid">
				<simple>${header.JMSTimestamp}</simple>
			</setHeader>
			<setHeader headerName="EmpId" id="_setHeaderEmpId">
				<xpath resultType="String">/employees/employee/id</xpath>
			</setHeader>
			<setHeader headerName="EmpName" id="_setHeaderEmpName">
				<xpath resultType="String">/employees/employee/name</xpath>
			</setHeader>
			<setHeader headerName="XmlPayload" id="_setHeaderXmlPayload">
				<simple>${body}</simple>
			</setHeader>
			<unmarshal id="_unmarshal1" ref="jaxData" />
			<to id="_toXmlToJson" uri="direct:xmlToJSON" />
			<toD id="insertMessageIntoDB" uri="sqlComponent:{{sql.insertEmployee}}" />
			<log id="_logMessage" message="Record has been inserted successfully." />
		</route>
		<route id="xmlToJSON">
			<from id="_from2" uri="direct:xmlToJSON" />
			<marshal id="_marshal1" ref="jack" />
			<convertBodyTo id="_convertBodyTo1" type="String" />
			<setHeader headerName="JsonPayload" id="_setHeaderJsonPayload">
				<simple>${body}</simple>
			</setHeader>
			<log id="_logXmlToJson" message="Xml to JSON is :: \n${body}" />
		</route>
	</camelContext>
</blueprint>

How to create xsd schema file

We need to create xsd schema file for generating java POJO classes for unmarshalling and marshalling purpose.

e.g. we have employees schema as below. we can create this either using tool or mannually.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="employees">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="employee">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="id" type="xs:unsignedShort" />
              <xs:element name="name" type="xs:string" />
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

How to generate JaxB data from xsd schema

From IDE you may right click on xsd schema file and can generate the JaxB data class with ObjectFactory.java or you may use maven plug-in for this.

How to generate jaxB classes from xsd schema

How to unmarshal xml to Java POJO classes

For unmarshalling xml to Java POJO classess we need to add below dataFormats in our camel-context.xml file.

<dataFormats>
	<jaxb contextPath="com.the.basic.tech.info.jaxb.beans" id="jaxData" />
	<json enableJaxbAnnotationModule="true" id="jack" library="Jackson" prettyPrint="true" unmarshalTypeName="com.the.basic.tech.info.beans.pojo.Employees" />
</dataFormats>

How to marshal Java POJO to JSON objects

For marshalling Java POJO classess to JSON objects we need to add below dataFormats in our camel-context.xml file.

<dataFormats>
	<jaxb contextPath="com.the.basic.tech.info.jaxb.beans" id="jaxData" />
	<json enableJaxbAnnotationModule="true" id="jack" library="Jackson" prettyPrint="true" unmarshalTypeName="com.the.basic.tech.info.beans.pojo.Employees" />
</dataFormats>

Employees POJO Classes

Below Java POJO classes need to added for marshalling.

package com.the.basic.tech.info.beans.pojo;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.annotation.JsonRootName;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;



@XmlRootElement(name = "employees")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(propOrder={
    "employee"
})
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonPropertyOrder({
	"employee"
})
@JacksonXmlRootElement(localName="employees")
@JsonRootName(value ="employees")
public class Employees
{

	@JsonProperty("employee")
    private Employee employee;

	public Employee getEmployee() {
		return employee;
	}

	public void setEmployee(Employee employee) {
		this.employee = employee;
	}   
    
}
package com.the.basic.tech.info.beans.pojo;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;


@XmlRootElement(name = "employee")		
@XmlAccessorType(XmlAccessType.PROPERTY)		
@XmlType(propOrder={		
    "id",		
    "name"	
})
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonPropertyOrder({
    "id",
    "name"
})
public class Employee
{

	@JsonProperty("id")
    private String id;
    @JsonProperty("name")
    private String name;
    
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	
    
}

How to use XPath expressions and predicates for extracting attributes value from XML payload

We need following maven dependencies in pom.xml for using XPath expressions and other marshalling and unmarshalling transformation.

<dependency>
	<groupId>org.apache.camel</groupId>
	<artifactId>camel-jaxb</artifactId>
</dependency>
<dependency>
	<groupId>org.apache.camel</groupId>
	<artifactId>camel-jackson</artifactId>
</dependency>
<dependency>
	<groupId>org.apache.camel</groupId>
	<artifactId>camel-jacksonxml</artifactId>
</dependency>

In following camel route lines we are extracting id and name attributes values using xpath and setting them into Header.

<setHeader headerName="EmpId" id="_setHeaderEmpId">
  <xpath resultType="String">/employees/employee/id</xpath>
</setHeader>
<setHeader headerName="EmpName" id="_setHeaderEmpName">
  <xpath resultType="String">/employees/employee/name</xpath>
</setHeader>

How to create database schema for storing records in MySQL database

We need to execute below database queries for creating schema and table structure in MySql database.

CREATE TABLE employees (empId VARCHAR(10) NOT NULL, empName VARCHAR(100) NOT NULL, xmlPayload VARCHAR(1000), jsonPayload VARCHAR(1000), created timestamp, correlationid VARCHAR(200));
MySQL - Create database 
schema using workbench

How to implement sql component for inserting records in MySQL database

Once we have datasource in camel-beans.xml file with bean id e.g. sqlComponent we can use the component in blueprint camel context file for executing SQL query.

<toD id="insertMessageIntoDB" uri="sqlComponent:{{sql.insertEmployee}}" />

{{sql.insertEmployee}} – we are reading SQL query from property file camel.blueprint.mysql.bundle.cfg

How to build the bundle

Following command to be run for build our fuse bundle.

D:\localworkspace\fuse-apache-camel-mysql-integration>mvn clean install
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Camel Blueprint MySQL Quickstart 1.0.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ camel-blueprint-mysql ---
[INFO] Deleting D:\localworkspace\fuse-apache-camel-mysql-integration\target
[INFO]
[INFO] --- maven-resources-plugin:3.0.1:resources (default-resources) @ camel-blueprint-mysql ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 8 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.5.1:compile (default-compile) @ camel-blueprint-mysql ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 4 source files to D:\localworkspace\fuse-apache-camel-mysql-integration\target\classes
[INFO]
[INFO] --- maven-resources-plugin:3.0.1:testResources (default-testResources) @ camel-blueprint-mysql ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory D:\localworkspace\fuse-apache-camel-mysql-integration\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.5.1:testCompile (default-testCompile) @ camel-blueprint-mysql ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.19.1:test (default-test) @ camel-blueprint-mysql ---
[INFO] No tests to run.
[INFO]
[INFO] --- maven-bundle-plugin:3.2.0:bundle (default-bundle) @ camel-blueprint-mysql ---
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) @ camel-blueprint-mysql ---
[INFO] Installing D:\localworkspace\fuse-apache-camel-mysql-integration\target\camel-blueprint-mysql-1.0.0-SNAPSHOT.jar to C:\Users\.m2\repository\com\the\basic\tech\info\camel-blueprint-mysql\1.0.0-SNAPSHOT\camel-blueprint-mysql-1.0.0-SNAPSHOT.jar
[INFO] Installing D:\localworkspace\fuse-apache-camel-mysql-integration\pom.xml to C:\Users\.m2\repository\com\the\basic\tech\info\camel-blueprint-mysql\1.0.0-SNAPSHOT\camel-blueprint-mysql-1.0.0-SNAPSHOT.pom
[INFO]
[INFO] --- maven-bundle-plugin:3.2.0:install (default-install) @ camel-blueprint-mysql ---
[INFO] Installing com/the/basic/tech/info/camel-blueprint-mysql/1.0.0-SNAPSHOT/camel-blueprint-mysql-1.0.0-SNAPSHOT.jar
[INFO] Writing OBR metadata
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 17.094 s
[INFO] Finished at: 2021-07-24T23:11:25+05:30
[INFO] Final Memory: 29M/258M
[INFO] ------------------------------------------------------------------------

D:\localworkspace\fuse-apache-camel-mysql-integration>

Copy application’s config files to /etc/ folder

For running our bundle in Red Hat Jboss Fuse ESB we need to copy bundle’s configurations files to /etc/ folder of the fuse.

Red Hat JBoss Fuse etc/ directory

How to create the features.xml and add into karaf container using features:addurl command

First of all we need to create the features.xml file for build and deployment our bundle in apache karaf container in fuse esb.

<?xml version="1.0" encoding="UTF-8"?>
<features xmlns="http://karaf.apache.org/xmlns/features/v1.0.0" name="custom-repo">
	<feature name="camel-blueprint-mysql">
		<feature>camel-core</feature>
		<feature>camel-blueprint</feature>
		<feature>camel-jaxb</feature>
		<feature>camel-jackson</feature>
		<feature>camel-jacksonxml</feature>
		<feature>camel-jms</feature>
		<feature>jasypt-encryption</feature>
		<feature>activemq</feature>
		<feature>activemq-client</feature>
		<feature>camel-sql</feature>
		<bundle>wrap:mvn:mysql/mysql-connector-java/8.0.22</bundle>
		<bundle>wrap:mvn:commons-dbcp/commons-dbcp/1.4</bundle>
		<bundle>wrap:mvn:commons-pool/commons-pool/1.6</bundle>
		<bundle>mvn:com.the.basic.tech.info/camel-blueprint-mysql/1.0.0-SNAPSHOT</bundle>
	</feature>
</features>

feature name will be used for installing the bundle in fuse and we following command to be executed over karaf prompt for adding features file.

JBossFuse:karaf@root> features:addurl file:D:/localworkspace/fuse-apache-camel-mysql-integration/src/main/resources/features.xml

Now, we can install our bundle.

JBossFuse:karaf@root> features:install camel-blueprint-mysql

We can see bundle under the list of bundles with its ID.

Bundle list

Application Testing & Logs

We can monitor application/bundle logs in fuse.log (D:\Software\jboss-fuse-6.3.0.redhat-187\data\log\fuse.log)

2021-07-24 23:16:07,443 | INFO  | pool-40-thread-1 | DefaultRuntimeEndpointRegistry   | 232 - org.apache.camel.camel-core - 2.17.0.redhat-630187 | Runtime endpoint registry is in extended mode gathering usage statistics of all incoming and outgoing endpoints (cache limit: 1000)
2021-07-24 23:16:07,505 | INFO  | pool-40-thread-1 | BlueprintCamelContext            | 232 - org.apache.camel.camel-core - 2.17.0.redhat-630187 | AllowUseOriginalMessage is enabled. If access to the original message is not needed, then its recommended to turn this option off as it may improve performance.
2021-07-24 23:16:07,508 | INFO  | pool-40-thread-1 | DefaultStreamCachingStrategy     | 232 - org.apache.camel.camel-core - 2.17.0.redhat-630187 | StreamCaching in use with spool directory: D:\Software\jboss-fuse-6.3.0.redhat-187\bin\..\data\tmp\camel\camel-tmp-6430a4f7-eab7-4415-87ae-83cc8c0305c6 and rules: [Spool > 128K body size]
2021-07-24 23:16:07,649 | INFO  | pool-40-thread-1 | BlueprintCamelContext            | 232 - org.apache.camel.camel-core - 2.17.0.redhat-630187 | Route: inputQueue started and consuming from: Endpoint[activemq://com.the.basic.tech.info.inputQueue]
2021-07-24 23:16:07,654 | INFO  | pool-40-thread-1 | BlueprintCamelContext            | 232 - org.apache.camel.camel-core - 2.17.0.redhat-630187 | Route: xmlToJSON started and consuming from: Endpoint[direct://xmlToJSON]
2021-07-24 23:16:07,654 | INFO  | pool-40-thread-1 | BlueprintCamelContext            | 232 - org.apache.camel.camel-core - 2.17.0.redhat-630187 | Total 2 routes, of which 2 are started.
2021-07-24 23:16:07,656 | INFO  | pool-40-thread-1 | BlueprintCamelContext            | 232 - org.apache.camel.camel-core - 2.17.0.redhat-630187 | Apache Camel 2.17.0.redhat-630187 (CamelContext: fuse-apache-camel-mysql-integration-context) started in 0.249 seconds

Login to Red Hat JBoss Fuse admin console

For publising xml message to the queue we can login to hawtio console.

Url: http://localhost:8181/hawtio/welcome

Red Hat JBoss Fuse Admin Console

Username/Password: admin/admin. Under ActiveMQ tab we can see queues list. e.g. com.the.basic.tech.info.inputQueue

Red Hat JBoss Fuse ActiveMQ Console

For publishing inputMessage.xml (below) click on queue and Send button.

<?xml version="1.0" encoding="UTF-8"?>
<employees>
   <employee>
      <id>10001</id>
      <name>Mark</name>
   </employee>
</employees>
Red Hat JBoss Fuse ActiveMQ console

Once, we click on Send message button – inputMessage.xml will be published to the queue and it can be consumed by our Camel route consumer. We can see in fuse logs.

In MySQL database record will be inserted.

MySQL Database

Download Source Code (Attached)

Keep learning :). Have a great Day.