Optional NuvlaBox component that consumes data from a specified MQTT broker and topic, double checks the data structure against FIWARE's data schemas, and sends data to a specified endpoint
At its core, the basic deployment of this component is achieved by:
docker run --rm --network <mqtt-broker-network> nuvlabox/mqtt-fiware-bridge:<tag> --mqtt-host <mqtt.broker> --mqtt-topic <topic>
where:
- mqtt-broker-network: is the Docker network where your MQTT broker container is running. This is only applicable if you are collecting the MQTT messages from your local container cluster. If the MQTT broker is reachable via IP or DNS name, then you can ditch the
--network
argument - tag: the Docker image tag
- mqtt.broker: the endpoint for the MQTT broker
- topic: the MQTT topic to subscribe to
At the moment, this image is simply taking MQTT messages, validating them through FIWARE, and printing them if successful.
TODO: Output connectors will be coming soon
If you'd like to build your own bridge, you can base your own Docker image on this one:
-
build your Dockerfile with
FROM nuvlabox/mqtt-fiware-bridge:<tag>
-
make sure you set your own
ENTRYPOINT
to replace this image's default one -
your entrypoint script must inherit the mqtt_fiware_bridge's
MFB.MqttFiwareBridge
class. For example (as in code/main.py)from mqtt_fiware_bridge import MFB class YourBridge(MFB.MqttFiwareBridge): def __init__(self, **kwargs): super(YourBridge, self).__init__(**kwargs)
-
you should override the
do_something
abstract method, to meet your needs. This method is executed everytime there's a new MQTT message, after it is validated successfully against FIWARE. So your class from above becomes:from mqtt_fiware_bridge import MFB class YourBridge(MFB.MqttFiwareBridge): def __init__(self, **kwargs): super(YourBridge, self).__init__(**kwargs) def do_something(self, message): # do whatever you want with the message here... # it has already been validated
-
finally, from your main application, simply instantiate YourBridge class, and
connect()
to subscribe to the MQTT broker and start listening to messages indefinitelyyour_client = YourBridge() your_client.connect() # endless loop
Copyright © 2021, SixSq SA