... optimizing your manufacturing processes with modular digital twins composed of expert assets...
Edge deployment for MQTT->PostgreSQL transfer using Camel
Microservice related to Additive Manufacturing in the context of IT Security
Description:
Edge deployment for MQTT->PostgreSQL transfer using Camel
Classification: Other
Type: Other
- beans:
- name: mydatabase
type: org.apache.commons.dbcp.BasicDataSource
properties:
url: "jdbc:postgresql://${POSTGRESQL_HOST}:${POSTGRESQL_PORT}/${POSTGRESQL_DATABASE}"
driver-class-name: "org.postgresql.Driver"
username: "${POSTGRESQL_USERNAME}"
password: "${POSTGRESQL_PASSWORD}"
- route:
id: "YAML MQTT->PostgreSQL route"
auto-startup: true
from:
uri: "paho-mqtt5:${MQTT_TOPIC}"
parameters:
brokerUrl: "tcp://${MQTT_HOST}:${MQTT_PORT}"
retained: "true"
steps:
- unmarshal:
gzipDeflater: {}
- convertBodyTo:
type: "String"
charset: "Cp1250"
- set-header:
name: "identifier"
expression:
jsonpath: "$.identifier"
- set-header:
name: "event_timestamp"
expression:
jsonpath: "$.timestamp"
- set-header:
name: "source"
expression:
jsonpath: "$.source"
- set-header:
name: "data"
expression:
jsonpath: "$.data"
- set-header:
name: "config"
expression:
jsonpath: "$.config"
- set-body:
simple: ${body.substring(0,100)}
- log: "Message: ${body}"
- set-body:
simple: "INSERT INTO ${POSTGRESQL_TABLE}(identifier, event_timestamp, source, data, config) VALUES ('${header[identifier]}', ${header[event_timestamp]}, '${header[source]}', '${header[data]}', '${header[config]}');"
- to:
uri: "jdbc:mydatabase"
parameters:
allowNamedParameters: True
useHeadersAsParameters: True
#!/bin/bash
echo "Starting Camel Microservice..."
printenvcp /route-templates/* /routes/
sed -i 's/\${MQTT_HOST}/'${MQTT_HOST}'/g' /routes/mqtt-postgres-route.yaml
sed -i 's/\${MQTT_PORT}/'${MQTT_PORT}'/g' /routes/mqtt-postgres-route.yaml
sed -i 's/\${MQTT_TOPIC}/'${MQTT_TOPIC}'/g' /routes/mqtt-postgres-route.yaml
sed -i 's/\${POSTGRESQL_HOST}/'${POSTGRESQL_HOST}'/g' /routes/mqtt-postgres-route.yaml
sed -i 's/\${POSTGRESQL_PORT}/'${POSTGRESQL_PORT}'/g' /routes/mqtt-postgres-route.yaml
sed -i 's/\${POSTGRESQL_DATABASE}/'${POSTGRESQL_DATABASE}'/g' /routes/mqtt-postgres-route.yaml
sed -i 's/\${POSTGRESQL_TABLE}/'${POSTGRESQL_TABLE}'/g' /routes/mqtt-postgres-route.yaml
sed -i 's/\${POSTGRESQL_USERNAME}/'${POSTGRESQL_USERNAME}'/g' /routes/mqtt-postgres-route.yaml
sed -i 's/\${POSTGRESQL_PASSWORD}/'${POSTGRESQL_PASSWORD}'/g' /routes/mqtt-postgres-route.yaml
echo "mqtt-postgres-route.yaml: "
cat /routes/mqtt-postgres-route.yaml
# echo $MQTT_CLIENT_CERTIFICATE | base64 --decode > /usr/src/keystore.jks
# echo "Java keystore file: "
# ls -l /usr/src/keystore.jks
# JAVA_TOOL_OPTIONS=-Xmx1G -Djavax.net.ssl.trustStore=/usr/src/keystore.jks -Djavax.net.ssl.trustStorePassword=changeit -Djavax.net.ssl.keyStore=/usr/src/keystore.jks -Djavax.net.ssl.keyStorePassword=changeit
echo "Starting Apache Camel..."
java -jar /usr/src/bb-apache-camel-0.0.1.jar
echo Done
Local IP of MQTT broker
Port of the MQTT broker
MQTT topic to read data from
Local IP address of the PostgreSQL database
Port of the PostgreSQL database
Database name where to put data
Database table where to put data
Username to use the database
Database password to use
MQTT Client certificate
01. services: 02. camel: 03. command: bash /usr/src/init.sh 04. container_name: camel 05. environment: 06. - MQTT_HOST=${MQTT_HOST} 07. - MQTT_PORT=${MQTT_PORT} 08. - MQTT_TOPIC=${MQTT_TOPIC} 09. - POSTGRESQL_HOST=${POSTGRESQL_HOST} 10. - POSTGRESQL_PORT=${POSTGRESQL_PORT} 11. - POSTGRESQL_DATABASE=${POSTGRESQL_DATABASE} 12. - POSTGRESQL_TABLE=${POSTGRESQL_TABLE} 13. - POSTGRESQL_USERNAME=${POSTGRESQL_USERNAME} 14. - POSTGRESQL_PASSWORD=${POSTGRESQL_PASSWORD} 15. - MQTT_CLIENT_CERTIFICATE=${MQTT_CLIENT_CERTIFICATE} 16. - JAVA_TOOL_OPTIONS=-Xmx1G 17. image: emodimark/apache-camel:3.20.5 18. version: '3' 19.