Skip to content

Latest commit

 

History

History
142 lines (106 loc) · 4.84 KB

camel.md

File metadata and controls

142 lines (106 loc) · 4.84 KB

Camel

Prerequisites

In order to run, compiled, and debug Camel routes, it is necessary to satisfy the following prerequisites:

Known Limitations

  • Amazon ECR is not supported yet by Kamel, use Docker Hub instead.
  • Only one Java source file is supported. This limitation can be bypassed by building dependencies locally as .jar.
    • Example: kamel run -d file://path/to/dependency.jar Route.java

Exchange Pattern

There are two Message Exchange Patterns you can use in messaging.

According to the Enterprise Integration Patterns, they are:

  • Event Message (or one-way)
  • Request-Reply

In Camel, we have an org.apache.camel.ExchangePattern enumeration which can be configured on the exchangePattern property on the Message Exchange indicating if a message exchange is a one-way Event Message (InOnly) or a Request-Reply message exchange (InOut).

More information in the official documentation.

Camel K

When deployed in Kubernetes the Camel routes are deployed using Camel K. Camel K does not deploy the whole Maven/Quarkus/Spring-boot project but only the route definition. To do so it needs a special syntax in the .java files to know which package to install.

Example:

// camel-k: dependency=mvn:org.apache.camel.quarkus:camel-quarkus-bean
// camel-k: dependency=mvn:org.apache.camel.quarkus:camel-quarkus-seda
// camel-k: dependency=mvn:org.apache.camel.quarkus:camel-quarkus-stream
// camel-k: dependency=mvn:org.apache.camel.quarkus:camel-quarkus-paho-mqtt5
// camel-k: dependency=mvn:org.apache.camel.quarkus:camel-quarkus-openapi-java

package com.opendatahub.inbound.mqtt;

import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.paho.mqtt5.PahoMqtt5Constants;

It's also recommended to keep the route in a single file. Reference: Blog Article.

How to deploy routes via Camel K CLI

Create secret common to all routes:

RABBITMQ_HOST="$(kubectl get secret -n core rabbitmq-svcbind -o jsonpath='{.data.host}' | base64 -d)"
RABBITMQ_PORT="$(kubectl get secret -n core rabbitmq-svcbind -o jsonpath='{.data.port}' | base64 -d)"
RABBITMQ_USER="$(kubectl get secret -n core rabbitmq-svcbind -o jsonpath='{.data.username}' | base64 -d)"
RABBITMQ_PASS="$(kubectl get secret -n core rabbitmq-svcbind -o jsonpath='{.data.password}' | base64 -d)"
RABBITMQ_CLUSTER_URL=$RABBITMQ_HOST:$RABBITMQ_PORT
kubectl create secret generic kamel-credentials \
  --namespace core \
  --from-literal=rabbitmq.cluster="$RABBITMQ_CLUSTER_URL" \
  --from-literal=rabbitmq.user="$RABBITMQ_USER" \
  --from-literal=rabbitmq.pass="$RABBITMQ_PASS" 

Run the MQTT Route

kamel run \
  --namespace core \
  --name mqtt-route \
  --property mqtt.url='tcp://mosquitto:1883' \
  --property secret:kamel-credentials \
  --property rabbitmq.clientName='mqtt-route' \
    infrastructure/inbound/src/main/java/com/opendatahub/inbound/mqtt/MqttRoute.java

Run the REST Route (REST and WebSocket)

kamel run \
  --namespace core \
  --name rest-route \
  --property secret:kamel-credentials \
  --property rabbitmq.clientName='rest-route' \
    infrastructure/inbound/src/main/java/com/opendatahub/inbound/rest/RestRoute.java

Run the Fastline Route (WebSocket)

kamel run \
  --namespace core \
  --name fastline-route \
  --property secret:kamel-credentials \
  --property rabbitmq.clientName='fastline-route' \
    infrastructure/router/src/main/java/com/opendatahub/outbound/fastline/FastlineRoute.java

Run the Router Route (RabbitMQ)

kamel run \
  --namespace core \
  --name router-route \
  --property secret:kamel-credentials \
  --property rabbitmq.clientName='router-route' \
    infrastructure/router/src/main/java/com/opendatahub/outbound/router/RouterRoute.java

Run the Update Route

kamel run \
  --namespace core \
  --name update-route \
  --property secret:kamel-credentials \
  --property rabbitmq.clientName='update-route' \
    infrastructure/router/src/main/java/com/opendatahub/outbound/update/UpdateRoute.java

Delete Camel Routes

It's not possible to scale down the Kamel integration from Kubernetes. If we need to stop a route we have to tell Kamel to delete the whole route, which reflects in deleting the Kubernetes deployment.

kamel delete <route-name>

Useful Resources