From 251c287477941400dc5f2b997f7d513b8bad6d60 Mon Sep 17 00:00:00 2001 From: Sam Yaple Date: Fri, 24 Mar 2017 16:22:33 +0000 Subject: [PATCH] Add an example not using websockets Websockets are borked at the moment and that caused a bit of confusion reading the docs and attempting to make this work. Add a non-websockets example. Change-Id: If85b5f91ba27fb90b8b86416037f6abee4dd6e2e --- doc/source/firehose.rst | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/doc/source/firehose.rst b/doc/source/firehose.rst index 0c347b9ea4..e94244af69 100644 --- a/doc/source/firehose.rst +++ b/doc/source/firehose.rst @@ -117,6 +117,35 @@ For example, to subscribe to every topic on the firehose you would run:: You can adjust the value of the topic parameter to make what you're subscribing to more specific. +MQTT Protocol Example +--------------------- +You can also use the paho-mqtt python library to subscribe to MQTT messages +fairly easily. For example this script will subscribe to all topics on the +firehose and print it to STDOUT + +.. code-block:: python + :emphasize-lines: 12,17 + + import paho.mqtt.client as mqtt + + + def on_connect(client, userdata, flags, rc): + print("Connected with result code " + str(rc)) + client.subscribe('#') + + def on_message(client, userdata, msg): + print(msg.topic+" "+str(msg.payload)) + + # Create a websockets client + client = mqtt.Client() + client.on_connect = on_connect + client.on_message = on_message + + # Connect to the firehose + client.connect('firehose.openstack.org') + # Listen forever + client.loop_forever() + Websocket Example ----------------- In addition to using the raw MQTT protocol firehose.o.o provides a websocket