This repository is a fork of the OpenFaaS MQTT Connector with some features and changes:
- Support for namespace filtering using flusflas/connector-sdk and
namespace
environment variable.- Configurable rebuild interval for functions-topics mapping.
- Switch from Go Dep to Go Module.
- Add
async-callback-url
command argument to set an optional callback URL for asynchronous invocations.- Fix the behavior with topic subscriptions: before, a default message handler was handling every message on every topic (which was equivalent to a subscription to
#
). Now, a subscription per topic is created from the comma-separated list of topics, and a non-default handler is used to only handle the messages on the subscribed topics.
This is an MQTT connector for OpenFaaS. Once configured and deployed it will deliver messages from selected topics to OpenFaaS functions.
There are various other connectors available for OpenFaaS which form "triggers" for event-driven architectures.
Prior work:
This is inspired by prior work by Alex Ellis: Collect, plot and analyse sensor readings from your IoT devices with OpenFaaS
Component parts:
- connector-sdk from OpenFaaS
- The Eclipse provides a test broker
- Eclipse's paho.mqtt.golang package provides the connection to MQTT.
See helm chart for deployment instructions. Then continue at "Test the connector".
TAG=0.2.0 make build push
go build
export TOPIC=""
export GATEWAY_PASS=""
./mqtt-connector --gateway http://192.168.0.35:8080 \
--gw-password $GATEWAY_PASS \
--broker tcp://test.mosquitto.org:1883 \
--topic $TOPIC
Annotate a function with the annotation topic: $TOPIC
<- where $TOPIC
is the MQTT topic you care about.
2019/12/03 16:43:26 Topic: topic Broker: tcp://test.mosquitto.org:1883
2019/12/03 16:43:29 Invoking (http://192.168.0.35:8080) on topic: "topic", value: "{\"sensor\": \"s1\", \"humidity\": \"52.09\", \"temp\": \"23.200\", \"ip\": \"192.168.0.40\", \"vdd33\": \"65535\", \"rssi\": -45}"
2019/12/03 16:43:29 Invoke function: print-out
Send: "{\"sensor\": \"s1\", \"humidity\": \"52.09\", \"temp\": \"23.200\", \"ip\": \"192.168.0.40\", \"vdd33\": \"65535\", \"rssi\": -45}"
2019/12/03 16:43:29 connector-sdk got result: [200] topic => print-out (24) bytes
[200] topic => print-out
{"temperature":"23.200"}
2019/12/03 16:43:29 tester got result: [200] topic => print-out (24) bytes
This data was generated on the topic topic
by my NodeMCU device which publishes sensor data.
A node12
function named print-out
returned the temperature as reported.
export NAMESPACE="alexellis2" # Or set your own registry/username
TAG=0.1.1 make build push
MIT