pahoMqttSub icon

pahoMqttSub

Paho MQTT Subscriber
pahoMqttSubAxon funcs

Registered StackHub users may elect to receive email notifications whenever a new package version is released or a comment is posted on the forum.

There is 1 watcher.

v1.0.7

pahoMqttPublish
pahoMqttPublish(publisher, message, topic)

Publish a single Str message to a topic using a previously constructed pahoMqttPublisher instance

The Ref provided must match a record found in folio.

Examples:

pahoMqttPublisher({brokerUrl:`tcp://host:1883`, username:"username", password:"password", qos:1, retained:true, clientId:"myClientId"}).pahoMqttPublish("myMessage","myTopic")

Side effects:

  • The message is published to the topic chosen
Fantom signature:
@Axon { admin=true; } static Void pahoMqttPublish(Publisher publisher, Str message, Str topic)
pahoMqttPublisher
pahoMqttPublisher(cfg)

Create a new pahoMqttPublisher instance which can be used to publish multiple messages. It is the responsibility of the caller to close this publisher when publishing is complete, using the pahoMqttPublisherClose call.

The brokerUrl must be provided and can be a Uri or a Str.

If username is provided, then password is also expected.

The cleanSession is optional and will default to false.

The retained is optional and will default to false.

The qos is optional and will default to 1.

The clientId is optional and will default to a random UUID if not supplied.

Examples:

pahoMqttPublisher({brokerUrl:`tcp://host:1883`, username:"username", password:"password", qos:1, retained:true, clientId:"myClientId"})

Side effects:

  • Creates a new Paho MQTT Client instance, connected and ready to publish messages.
Fantom signature:
@Axon { admin=true; } static Publisher pahoMqttPublisher(Dict cfg)
pahoMqttPublisherClose
pahoMqttPublisherClose(publisher)

Close a previously constructed pahoMqttPublisher instance

Examples:

pahoMqttPublisher({brokerUrl:`tcp://host:1883`, username:"username", password:"password", qos:1, retained:true, clientId:"myClientId"}).pahoMqttPublisherClose()

Side effects:

  • The pahoMqttPublisher instance is closed and can no longer be used to publish messages
Fantom signature:
@Axon { admin=true; } static Void pahoMqttPublisherClose(Publisher publisher)
pahoMqttSubscriberAdd
pahoMqttSubscriberAdd(sub, password: null)

Create a new pahoMqttSubscriber record and register it within the list of Subscribers being managed.

The brokerUrl must be provided and must be a URI.

The topics must be provided and must be a List of Str.

The parser must be provided. This should match the name of an Axon function that takes two Str parameters: (topic, message). This parser will be used for all messages from all the topics listed.

The qos is optional and will default to 1. See MQTT Docs for details on QOS.

The clientId is optional and will default to a random UUID if not supplied.

If username is provided, then the optional second parameter for password is also expected. These will be supplied to the broker on connection. If you have a non-authenticating broker, just leave out username and drop the second parameter.

Examples:

pahoMqttSubscriberAdd({brokerUrl:`tcp://host:1883`, topics:["topic/one","topic/two"], parser:"myMsgParser", qos:1})
pahoMqttSubscriberAdd({brokerUrl:`tcp://host:1883`, topics:["topic/one","topic/two"], parser:"myMsgParser", clientId:"myClientId", username:"username"}, "password")

Side effects:

  • Adds a new record to folio with the marker tag pahoMqttSubscriber combined with the tags from the provided Dict
  • If a username and password are provided, the password will be stored in the password db keyed by the pahoMqttSubscriber folio record id.
Fantom signature:
@Axon { admin=true; } static Dict pahoMqttSubscriberAdd(Dict sub, Str? password := null)
pahoMqttSubscriberDelete
pahoMqttSubscriberDelete(ref)

Delete a Subscriber passing the Ref ID of the folio record corresponding to it.

The Ref provided must match a record found in folio.

Examples:

pahoMqttSubscriberDelete(@p:proj1:r:255481c1-42be3946)

Side effects:

  • Unsubscribes from all topics
  • Disconnects the Subscriber from the Broker
  • Deletes the record from folio
Fantom signature:
@Axon { admin=true; } static Void pahoMqttSubscriberDelete(Ref ref)
pahoMqttSubscriberStart
pahoMqttSubscriberStart(ref)

Start a Subscriber passing the Ref ID of the folio record corresponding to it.

The Ref provided must match a record found in folio.

Examples:

pahoMqttSubscriberStart(@p:proj1:r:255481c1-42be3946)

Side effects:

  • Connects the Subscriber to the Broker at the URL specified in its folio record
  • Subscribes to all topics listed
  • Returns the record with the transient running tag set to true if it succeeded in starting
Fantom signature:
@Axon { admin=true; } static Dict pahoMqttSubscriberStart(Ref ref)
pahoMqttSubscriberStartAll
pahoMqttSubscriberStartAll()

Start all Subscribers.

Examples:

pahoMqttSubscriberStartAll()

Side effects:

  • All Subscribers started
  • Returns the list of subscribers
Fantom signature:
@Axon { admin=true; } static Grid pahoMqttSubscriberStartAll()
pahoMqttSubscriberStop
pahoMqttSubscriberStop(ref)

Stop a Subscriber passing the Ref ID of the folio record corresponding to it.

The Ref provided must match a record found in folio.

Examples:

pahoMqttSubscriberStop(@p:proj1:r:255481c1-42be3946)

Side effects:

  • Unsubscribes from all topics
  • Disconnects the Subscriber from the Broker
  • Returns the record with the transient running tag set to false if it succeeded in stopping
Fantom signature:
@Axon { admin=true; } static Dict pahoMqttSubscriberStop(Ref ref)
pahoMqttSubscriberStopAll
pahoMqttSubscriberStopAll()

Stop all Subscribers.

Examples:

pahoMqttSubscriberStopAll()

Side effects:

  • All Subscribers stopped
  • Returns the list of subscribers
Fantom signature:
@Axon { admin=true; } static Grid pahoMqttSubscriberStopAll()

Packages by Cool Planet Clarity Ltd

Free packages