Assets

... optimizing your manufacturing processes with modular digital twins composed of expert assets...

icon

CNS-CAMEL-EGDE-DATA2-M

Edge deployment for MQTT->PostgreSQL transfer using Camel

Microservice related to Additive Manufacturing in the context of IT Security

Provided by SZTAKI - Institute for Computer Science and Control 1 year ago (last modified 11 months, 4 weeks ago); viewed 403 times and bound 1 time

Description:

Edge deployment for MQTT->PostgreSQL transfer using Camel

Classification: Other

Type: Other

Configuration Files
  • File path: /route-templates/mqtt-postgres-route.yaml
  • File content:

    - 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

  • File path: /usr/src/init.sh
  • File content:

    #!/bin/bash
    echo "Starting Camel Microservice..."
    printenv

    cp /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

Expected User's Input Parameters
MQTT_HOST

Local IP of MQTT broker

  • Type: text
  • Mandatory: Yes
MQTT_PORT

Port of the MQTT broker

  • Type: integer
  • Mandatory: Yes
MQTT_TOPIC

MQTT topic to read data from

  • Type: text
  • Mandatory: Yes
POSTGRESQL_HOST

Local IP address of the PostgreSQL database

  • Type: text
  • Mandatory: Yes
POSTGRESQL_PORT

Port of the PostgreSQL database

  • Type: integer
  • Mandatory: Yes
POSTGRESQL_DATABASE

Database name where to put data

  • Type: text
  • Mandatory: Yes
POSTGRESQL_TABLE

Database table where to put data

  • Type: text
  • Mandatory: Yes
POSTGRESQL_USERNAME

Username to use the database

  • Type: text
  • Mandatory: Yes
POSTGRESQL_PASSWORD

Database password to use

  • Type: text
  • Mandatory: Yes
MQTT_CLIENT_CERTIFICATE

MQTT Client certificate

  • Type: text
  • Mandatory: No
Container Deployment Information
  • Format: docker-compose
  • Data:
    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. 
  • GUI Microservice: No
  • Workload type: service
  • Opened ports: 30010