Skip to content

Axway-API-Management-Plus/mqtt-trigger

Repository files navigation

alt text alt text

Description

mqtt-trigger subscribes to MQTT topic(s) and calls an REST APIs

alt text

API Management Version Compatibility

This artefact can be used with every API Management Plus version

Prerequisites

  • docker 17.06 (and docker-compose)
  • MQTT Broker : activemq / rabbitmq / mosquitto / ...
  • Policy Engine : Axway API Gateway or custom engine (see [./tests/policy] )

Configure your policy engine

Triggers are set inside mqt-trigger.yml, for example all Messages on topic #simplest are forwarded to API Management. API Endpoint and other Parameters can be modified inside the mqtt-trigger.yml

See Axway API Gateway samples for mqtt in : ./api-gateway-policies/mqtt-trigger-apigw-policy.xml In API Gateway Policy Studio, please use Import Configuration Fragment to upload the policy

Start

Command Line

mqtt-trigger [OPTIONS]
Usage of ./mqtt-trigger:
  -conf string
    	conffile
  -http-headers string
    	headers ( 'key1 : value1, key2: value2' )
  -http-url string
    	Default prefix for url to forward messages ( http-url + trigger-name)
  -mqtt-broker string
    	Default MQTT broker url (mqtt://)
  -mqtt-client-id string
    	Default prefix to MQTT Client ID (client-id + '-' + trigger-name)
  -mqtt-password string
    	Default MQTT password
  -mqtt-username string
    	Default MQTT username

Test full environment with docker

docker-compose -f docker-compose.yml up

Configuration

By Configuration file

defaults:
  url: http://api:3000/api/topic
  headers:
  - "Content-Type: application/json"
  broker: mqtt://mosquitto:1883
  clientid: mqtt-trigger
  username: mqtt-trigger
  password : goodpass

triggers:
- name: simplest
- name: override
  topic: override-topic
  url: /override-uri
  clientid: override-id
  username: override-username
  headers:
  - "Content-Type: application/json"
  - "Override-Header : override-header-value"
- name: all
  topic: "all/#"
- name: activemq
  topic: activemq/#
  broker: mqtt://mosquitto:1883

Build standalone binary:

Prerequisites : golang

make install-deps
make

Build docker image

docker build -t mqtt-trigger:dev .
make docker
  -or-
docker build -t mqtt-trigger .

Test

make docker-test

Trigger conf

{
  name:    "string",
  topic:   "string",     // Default: <name>
  url:     "string",     // Default (conffile.Defaults.url || conffile.Defaults.url + -mqtt-url["/xxxx"] || -mqtt-url ) <name>
  headers: [ "string" ], // Default: "content-type: application/json" || conffile.Defaults.headers || -mqtt-headers

  broker:   "string",    // Default: conffile.Defaults.Broker || -mqtt-broker
  clientid: "string",    // Default: (conffile.Defaults.ClientID || -mqttclient-id) + <name>)
  username: "string",    // Default: conffile.Defaults.Username || -mqtt-username
  password: "string",    // Default: conffile.Defaults.Password || -mqtt-password
}

## Limitations

  • One Node only !!!! : No distribution across nodes
  • ClientID MUST be unique !
  • No TLS support for the trigger

Changelog

  • 0.0.4
    • add MQTT-TOPIC (replaces TOPIC), MQTT-CLIENT-ID, MQTT-USERNAME, TRIGGER-NAME headers
  • 0.0.3
    • add TOPIC header to the HTTP Post request
    • fix dynamic reload of config
  • 0.0.2
    • configuration file support with default
    • disabled etcd support
    • use docker 17.05 for compact build

Contributing

Please read Contributing.md for details on our code of conduct, and the process for submitting pull requests to us.

Team

alt text Axway Team

License

Apache License 2.0

About

Trigger a HTTP request for each message received in a MQTT topic

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •