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:
parent
251c287477
commit
70747ff558
@ -119,12 +119,15 @@ to more specific.
|
|||||||
|
|
||||||
MQTT Protocol Example
|
MQTT Protocol Example
|
||||||
---------------------
|
---------------------
|
||||||
You can also use the paho-mqtt python library to subscribe to MQTT messages
|
Interacting with firehose on the unecrpyted MQTT port is normally pretty easy in
|
||||||
fairly easily. For example this script will subscribe to all topics on the
|
most language bindings. Here are some examples that will have the same behavior
|
||||||
firehose and print it to STDOUT
|
as the CLI example above and will subscribe to all topics on the firehose and
|
||||||
|
print it to STDOUT.
|
||||||
|
|
||||||
|
|
||||||
|
Python
|
||||||
|
''''''
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
:emphasize-lines: 12,17
|
|
||||||
|
|
||||||
import paho.mqtt.client as mqtt
|
import paho.mqtt.client as mqtt
|
||||||
|
|
||||||
@ -146,6 +149,49 @@ firehose and print it to STDOUT
|
|||||||
# Listen forever
|
# Listen forever
|
||||||
client.loop_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
|
Websocket Example
|
||||||
-----------------
|
-----------------
|
||||||
In addition to using the raw MQTT protocol firehose.o.o provides a websocket
|
In addition to using the raw MQTT protocol firehose.o.o provides a websocket
|
||||||
|
Loading…
Reference in New Issue
Block a user