clojurewerkz.machine-head.client documentation

Key MQTT client functions: connection, subscription, publishing

connect

(connect uri client-id)(connect uri client-id opts)(connect uri client-id persister opts)
Instantiates a new client and connects to MQTT broker.

connected?

(connected? client)
Returns true if client is currently connected

disconnect

(disconnect client)(disconnect client timeout)
Disconnects from MQTT broker.

disconnect-and-close

(disconnect-and-close client)(disconnect-and-close client timeout)
Disconnects from MQTT broker and releases all resources.

generate-id

(generate-id)
Generates a client id

pending-delivery-tokens

(pending-delivery-tokens client)
Retuns pending message delivery tokens, if any.

If all messages were published successfully after last
client termination, returns an empty collection.

pending-messages

(pending-messages client)
Retuns pending messages, if any.

If all messages were published successfully after last
client termination, returns an empty collection.

prepare

(prepare uri client-id)(prepare uri client-id persister)
Instantiates a new client

publish

(publish client topic payload)(publish client topic payload qos)(publish client topic payload qos retained?)
Publishes a message to a topic.

subscribe

(subscribe client topics handler-fn)(subscribe client topics handler-fn {:keys [on-connection-lost on-delivery-complete]})
Subscribes to one or multiple topics (if `topics` is a collection
or sequence).

Provided handler function will be invoked with 3 arguments:

 * Topic message was received on
 * Immutable map of message metadata
 * Byte array of message payload

Options:

 * :on-delivery-complete:
 * :on-connection-lost: function that will be called when connection
                       to broker is lost

subscribe-with-qos

(subscribe-with-qos client topics qos handler-fn)(subscribe-with-qos client topics qos handler-fn {:keys [on-connection-lost on-delivery-complete]})
Subscribes to one or multiple topics (if `topics` is a collection
or sequence) with provided QoS level(s).

QoS level must be either an int (from 0 to 2) or a collection of ints from.

Provided handler function will be invoked with 3 arguments:

 * Topic message was received on
 * Immutable map of message metadata
 * Byte array of message payload

Options:

 * :on-delivery-complete:
 * :on-connection-lost: function that will be called when connection
                       to broker is lost

unsubscribe

(unsubscribe client topics)
Unsubscribes from one or multiple topics (if `topics` is a collection
or sequence)