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
File | broker.js |
Abstract | The ( mqtt ) broker is a central service receiving and distributing messages to all subscribed receipiens . Use the "brokerservice" module to start the broker . |
Author | Volker Böhm |
Copyright | Copyright ( c ) 2020 Volker Böhm |
License | This 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
Name | Type | Description |
---|---|---|
configuration |
Object |
configuration for the broker |
configuration properties
Name | Type | Attribute | Default | Description |
---|---|---|---|---|
port |
number, string |
port number the broker will listen on | ||
persistInterval |
number |
optional | 60 * 1000 | Intervall between persisting internal state to file in milliseconds . Persistance is not called if this value is 0 |
connections |
Object |
connection settings for the broker |
connections properties
Name | Type | Attribute | Default | Description |
---|---|---|---|---|
fileName |
string |
filename for persistence | ||
directory |
string |
directory ( file path ) for persistence | ||
replyTimeoutInMilliseconds |
number |
timeout to wait for an answer of a http call | ||
inFlightWindow |
number |
optional | 1 | amount of qos 1 and qos 2 messages send for the same topic at the same time |
pubrelTimeoutInMilliseconds |
number |
optional | one day | temeout to wait for a corresponding pubrel message |
maxRetryCount |
number |
amount of resend of messages before forcing a disconnect | ||
maxQueuSize |
number |
maximal amount of entries in a message queue | ||
log |
Object |
log 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
Name | Type | Description |
---|---|---|
host |
string |
name of the host ( or his ip ) |
port |
number |
port number to connect to |
on
on (event, callback)
Sets a callback .
on Parameters
Name | Type | Description |
---|---|---|
event |
string |
callback 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 |
callback |
function |
on throws
Type | Description |
---|---|
Error |
if the event is not supported |
Error |
if the callback is not 'function' |
run
run ()
Starts the broker . It will listen to message , send messages and periodically store its status