1.2.1 • Published 1 year ago

@mangar2/mqttservice v1.2.1

Weekly downloads
3
License
LGPL-3.0-or-later
Repository
github
Last release
1 year ago

Abstract

Library module to communicate with the mqtt broker . It includes Publish to send messsages to the broker and OnPublish to receive messages published by the broker

Contents

Meta

Filemqttservice.js
AbstractLibrary module to communicate with the mqtt broker . It includes Publish to send messsages to the broker and OnPublish to receive messages published by the broker
AuthorVolker Böhm
CopyrightCopyright ( c ) 2020 Volker Böhm
LicenseThis software is licensed under the GNU LESSER GENERAL PUBLIC LICENSE Version 3 . It is furnished "as is" , without any support , and with no warranty , express or implied , as to its usefulness for any purpose .

Callback definitions

ProcessMessage

ProcessMessage Parameters

NameTypeDescription
messageObjectthe message received
qos0, 1, 2the quality of service information
dup0, 1flag signaling duplicates

Class OnPublish

new OnPublish(listenerPort, logSettings, qos2PubrelTimeoutInSeconds)

Creates a new server receiving messages Supports registering a callback with on ( 'publish' , ( payload , qos ) = > { } ) called for each received message

OnPublish Parameters

NameTypeDescription
listenerPortnumberport to listen on
logSettingsObjectlogging settings
qos2PubrelTimeoutInSecondsnumbertime to delete qos2 related packageid´s from the qos2 queue . This will happen , if a pubrel does not follow the publish call for a this amount of seconds

OnPublish Members

NameTypedescription
logFilterLogFilterLogging filter
portnumberPort the server uses , only defined after listen has been called !

OnPublish Methods

close

close ()

Closes all connections

listen

listen ()

Starts to listen and wait for input

on

on (event, callback)

Sets a callback . Usually , there is no need to set anything here

on Parameters
NameTypeDescription
eventstringevent name , supported 'publish'
callbackProcessMessagecallback to be called , to process messages received

Class PublishMessage

new PublishMessage(host, port, configuration)

Creates a client for publishing messages

Example

//Publish the message with topic /a/a, value 1, reason "test", QoS 0, retain 0:
const publish = new PublishMessage('myhost', 10000, { retry: 60 })
result = await publish.publish(publishtoken, new Message("/a/a", 1, "test"), 0, 0);

PublishMessage Parameters

NameTypeDescription
hoststringhost name ( or ip )
portnumberport number
configurationObjectconfiguration options

configuration properties

NameTypeAttributeDefaultDescription
retrynumberoptional60amount of retries to send a message

PublishMessage Methods

close

async close ()

Closes the connection to the broker

publish

async publish (token, message, qos, retain, version)

Publishes a message with a defined quality of service automatically generating an id

publish Parameters
NameTypeDescription
tokenstringconnection token
messageObjectmessage to publish .
qosnumber0 , 1 , 2 quality of service
retainbooleanTrue , if message shall be retained for future subscriptions
versionstring, undefinedinterface version , supports 0 . 0 and 1 . 0 ( default )
publish throws
TypeDescription
stringon any connection error