1.4.0 • Published 2 years ago

@mangar2/broker v1.4.0

Weekly downloads
10
License
LGPL-3.0-or-later
Repository
github
Last release
2 years ago

Abstract

The ( mqtt ) broker is a central service receiving and distributing messages to all subscribed receipiens . Use the "brokerservice" module to start the broker .

Contents

Meta

Filebroker.js
AbstractThe ( mqtt ) broker is a central service receiving and distributing messages to all subscribed receipiens . Use the "brokerservice" module to start 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 .

Class Broker

new Broker(configuration)

Creates a new broker

Example

const configuration = {
     port: 10000,
     persistInterval: 0,
     connections: {
          directory: '.',
          fileName: 'broker',
          log: [
              {
                  module: 'received',
                  topic: '#'
              }
          ]
      }
  }
const broker = new Broker(configuration)
broker.run()

Broker Parameters

NameTypeDescription
configurationObjectconfiguration for the broker

configuration properties

NameTypeAttributeDefaultDescription
portnumber, stringport number the broker will listen on
persistIntervalnumberoptional60 * 1000Intervall between persisting internal state to file in milliseconds . Persistance is not called if this value is 0
connectionsObjectconnection settings for the broker

connections properties

NameTypeAttributeDefaultDescription
fileNamestringfilename for persistence
directorystringdirectory ( file path ) for persistence
replyTimeoutInMillisecondsnumbertimeout to wait for an answer of a http call
inFlightWindownumberoptional1amount of qos 1 and qos 2 messages send for the same topic at the same time
pubrelTimeoutInMillisecondsnumberoptionalone daytemeout to wait for a corresponding pubrel message
maxRetryCountnumberamount of resend of messages before forcing a disconnect
maxQueuSizenumbermaximal amount of entries in a message queue
logObjectlog settings

Broker Methods

close

async close ()

Closes the broker , stops listening

connect

connect (host, port)

Connects to a friendly broker and subscribs for all messages

connect Parameters
NameTypeDescription
hoststringname of the host ( or his ip )
portnumberport number to connect to

on

on (event, callback)

Sets a callback .

on Parameters
NameTypeDescription
eventstringcallback name ( supports 'send' and 'publish' ) 'send' is called to send data . This function is provided by the broker but could be overwritten 'publish' is called on receiving data . This function if provided by the broker but could be overwritten
callbackfunction
on throws
TypeDescription
Errorif the event is not supported
Errorif the callback is not 'function'

run

run ()

Starts the broker . It will listen to message , send messages and periodically store its status