Camel Integration
Introduction
Apache Camel is a powerful, lightweight integration framework that enables developers to seamlessly connect diverse systems and applications using well-established Enterprise Integration Patterns (EIPs). It simplifies complex integration challenges by providing a domain-specific language (DSL) to define routing and mediation rules in a readable, declarative manner.
Camel Integration Support
For Domain Services based on Java Spring Boot Stack 2.0, IBM DevOps Solution Workbench provides various capabilities, to easily integrate with the help of the Opensource integration framework Apache Camel
The extension is available for the following project types:
Enable Extension
Before using Apache Camel, you need to enable the Camel extension in the k5-project.yaml
file.
.....
camelIntegrationSupport:
enabled: true
The Camel extension will be automatically enabled when the Saga extension is enabled.
POM Dependencies
When camel integration extension is enabled the following dependencies will be added automatically to your project pom.xml file
<dependencies>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-core</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel.springboot</groupId>
<artifactId>camel-lra-starter</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel.springboot</groupId>
<artifactId>camel-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-log</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel.springboot</groupId>
<artifactId>camel-spring-security-starter</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-servlet</artifactId>
</dependency>
</dependencies>
Servlet Initialization
If you want to customize any servlet property for your local development edit application-local.yaml
camel:
servlet:
mapping:
enabled: true
context-path: /camel/*
servlet-name: customServlet
Deployment
You can customize the same properties for single deployment using API Configuration Management.
Use POST /api/cfg/v1/runtimes/{runtimeName}/solutions/{solutionAcronym}/configurations/{configurationName}
with body like the following
extraConfiguration:
camel:
servlet:
mapping:
enabled: true
context-path: /camel/*
servlet-name: customServlet
For application composition use Configuring components with Custom configuration
like the following
extraConfiguration:
camel:
servlet:
mapping:
enabled: true
context-path: /camel/*
servlet-name: customServlet
Camel Security
If you want to secure your camel routes you can enable camel security. Enable secure camel will make sure that all your camel routes like "servicePath/camel/firstRoute" are protected with authorization token
Check Servlet Initialization to customize your context path.
If you want to enable security for your local development edit application-local.yaml
feature:
secure-camel:
enabled: false
Deployment
You can enable security for single deployment using API Configuration Management.
Use POST /api/cfg/v1/runtimes/{runtimeName}/solutions/{solutionAcronym}/configurations/{configurationName}
feature:
secure-camel:
enabled: false
For application composition use Configuring components with Custom configuration
like the following
feature:
secure-camel:
enabled: false
Implement Camel Routes
Apache Camel is a powerful integration framework for Java Spring Boot applications, designed to simplify message routing and processing, an implementation stub is generated under "src/main/java/yourProject/camel/camelRoutes.java
Configure Camel Routes
In order to configure Apache camel route you can extend EndpointRouteBuilder
and override configuration()
method. For more details check the below Minio example
Example:
This example represents a use case where user needs to consume files from Minio bucket.
Steps
-
Enable Camel Extension
-
Configuration
- For local development you can use application-local.yaml
camel:
component:
minio:
endpoint: YOUR_MINIO_URL
proxyPort: YOUR_MINIO_PORT
access-key: YOUR_MINIO_ACCESS_KEY
secret-key: YOUR_MINIO_SECRET_KEY
bucket: YOUR_BUCKET_NAME- For Single deployment or application composition extend deployment environment
env:
variables:
secretKeyRef:
- variableName: camel.component.endpoint
secretName: k5-minio-configuration
secretKey: endpoint
optional: false
secretKeyRef:
- variableName: camel.component.proxyPort
secretName: k5-minio-configuration
secretKey: proxyPort
optional: false
- variableName: camel.component.access-key
secretName: k5-minio-configuration
secretKey: access-key
optional: false
- variableName: camel.component.secret-key
secretName: k5-minio-configuration
secretKey: secret-key
optional: false
- variableName: camel.component.bucket
secretName: k5-minio-configuration
secretKey: bucket
optional: false -
Add dependencies in your pom.xml
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-minio</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel.springboot</groupId>
<artifactId>camel-minio-starter</artifactId>
</dependency> -
Implementation
@Component
public class CamelRoutes extends EndpointRouteBuilder {
private String bucketName;
public CamelRoutes(@Value("${camel.component.minio.bucket}")String bucketName) {
this.bucketName = bucketName;
}
@Override
public void configure() throws Exception {
// Using minio
from(minio(bucketName).delay(1000L).deleteAfterRead(false))
.routeId("minio-consumer")
.autoStartup(false)
.log("the content is ${body}");
}
}
@RestController
public class TestMinioAPI {
private ProducerTemplate producerTemplate;
public TestMinioAPI(ProducerTemplate producerTemplate) {
this.producerTemplate = producerTemplate;
}
@PostMapping("/trigger-minio")
public String triggerMinioRoute() {
producerTemplate.sendBody("controlbus:route?routeId=minio-consumer&action=start", null);
return "MinIO route triggered!";
}
}
The Camel integration is only available for Domain Services (Java) based on Java Spring Boot Stack 2.0