Classes

Pubsub
DummyPubsub
PubsubServer

Pubsub

Kind: global class

new Pubsub(url, options)

Pubsub object provides client-side interface for talking to a MQTT Publish/Subscribe Server. It is a thin wrapper around the mqtt client

Param Type Description
url string The URL of the Pub/Sub service
options object additional options object
options.handlers object a dictionary of : for initializing subscriptions

pubsub.subscribe(topic, handler) ⇒ Promise

Subscribe to a given topic, passing in a callback to invoke upon reception of the message under the said topic.

Kind: instance method of Pubsub
Returns: Promise - - On successful subscription, the Promise resolves to the topic.

Param Type Description
topic String the topic to subscribe to
handler function the callback function to invoke when a message arrives under the given topic. The callback must have the signature function(message, topic, rawBuffer)

pubsub.unsubscribe(topic) ⇒ Promise

Unsubscribe from a given topic. If the client is not subscribed, it will immediately resolve and will not reject with an error

Kind: instance method of Pubsub
Returns: Promise - - the Promise always resolves to the topic regardless of the outcome.

Param Type Description
topic String the topic to unsubscribe from

pubsub.publish(topic, message) ⇒ Promise

Publish to a given topic. If the given message is not a Buffer object, it will try and JSON.stringify it.

Kind: instance method of Pubsub
Returns: Promise - - resolves to through on successful publish

Param Type Description
topic String the topic to publish to
message Object \ Buffer message to send (assumed to be a JSON-serializable object by default)

pubsub.kill() ⇒ Promise

Kill the Pubsub instance, closing the connection.

Kind: instance method of Pubsub
Returns: Promise - - the Promise always resolves true regardless of the outcome.

Pubsub.Server

PubsubServer is available as a property of Pubsub

Kind: static property of Pubsub

Pubsub.Dummy

DummyPubsub is available as a property of Pubsub

Kind: static property of Pubsub

DummyPubsub

Kind: global class

new DummyPubsub()

Dummy Pubsub used for instrumenting code without connecting.

  • does not extend Pubsub (i.e. not a subclass), this is a standalone definition
  • this object is created instead of actual Pubsub when user code is initialized as a Process via Code.run().
  • when user code is executed via Code.run(), it has an IPC channel to the master process. in that case, pubsub.publish is done by the master process, and the child process (this process) sends the message to the master process.

PubsubServer

Kind: global class

new PubsubServer()

PubsubServer is a thin wrapper around the Mosca Server

pubsubServer.kill() ⇒ Promise

Kill the PubsubServer

Kind: instance method of PubsubServer

results matching ""

    No results matching ""