Start firehose doc section for client on port 1883

This commit starts a new section in the firehose docs for client
examples on how to print all messages from the firehose to STDOUT. All
the other examples in the doc either use ssl or websockets. It's good
to have an example of how to just connect to the firehose on vanilla
mqtt.

Change-Id: Iba9fb10e75eae10efcd59b70b6b83589a077610f
This commit is contained in:
Matthew Treinish 2017-03-24 14:21:59 -04:00
parent 251c287477
commit 70747ff558
No known key found for this signature in database
GPG Key ID: FD12A0F214C9E177

View File

@ -119,12 +119,15 @@ 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
Interacting with firehose on the unecrpyted MQTT port is normally pretty easy in
most language bindings. Here are some examples that will have the same behavior
as the CLI example above and will subscribe to all topics on the firehose and
print it to STDOUT.
Python
''''''
.. code-block:: python
:emphasize-lines: 12,17
import paho.mqtt.client as mqtt
@ -146,6 +149,49 @@ firehose and print it to STDOUT
# Listen forever
client.loop_forever()
Haskell
'''''''
This requires the `mqtt-hs`_ library to be installed.
.. _mqtt-hs: https://hackage.haskell.org/package/mqtt-hs
.. code-block:: haskell
{-# Language DataKinds, OverloadedStrings #-}
module Subscribe where
import Control.Concurrent
import Control.Concurrent.STM
import Control.Monad (unless, forever)
import System.Exit (exitFailure)
import System.IO (hPutStrLn, stderr)
import qualified Network.MQTT as MQTT
topic :: MQTT.Topic
topic = "#"
handleMsg :: MQTT.Message MQTT.PUBLISH -> IO ()
handleMsg msg = do
let t = MQTT.topic $ MQTT.body msg
p = MQTT.payload $ MQTT.body msg
print t
print p
main :: IO ()
main = do
cmds <- MQTT.mkCommands
pubChan <- newTChanIO
let conf = (MQTT.defaultConfig cmds pubChan)
{ MQTT.cHost = "firehose.openstack.org" }
_ <- forkIO $ do
qosGranted <- MQTT.subscribe conf [(topic, MQTT.Handshake)]
forever $ atomically (readTChan pubChan) >>= handleMsg
terminated <- MQTT.run conf
print terminated
Websocket Example
-----------------
In addition to using the raw MQTT protocol firehose.o.o provides a websocket