npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

node-raft-over-mqtt

v1.2.1

Published

Implementing the Raft consensus algorithm over MQTT for building resilient and distributed systems across multiple nodes.

Downloads

14

Readme

Raft Node Presence Manager

A Node.js implementation for managing node presence in a distributed system using the Raft consensus algorithm and MQTT protocol.

Features

  • Manages node presence and active nodes in a distributed network using the MQTT protocol.
  • Implements the Raft consensus protocol for leader election and state management.
  • Provides easy-to-use methods to handle MQTT connections, subscriptions, and messaging.

Installation

Install the package via npm:

npm install node-raft-over-mqtt

Libraries Used

This project makes use of the following libraries:

  • node-mqtt-client: MQTT client for managing secure MQTT connections with certificate-based authentication.

Usage

Here's an example of how to use the NodePresenceManager and RaftNode classes:

Initialization

To set up the Raft node, create an instance and set the required properties.

const { MQTTClient, RaftNode } = require('node-raft-over-mqtt');

// Configure the MQTT client
const mqttClient = new MQTTClient();
mqttClient.host = 'broker.fabris.io';
mqttClient.port = 8883;
mqttClient.protocol = MQTTClient.Protocol.MQTTS;
mqttClient.certificateManager.loadCertificates(
  'authority.pem',
  'certificate.pem',
  'key.pem'
);
mqttClient.connect();

// Unique identifier for the node
const uuid = 'node-1';

// Initialize the Raft node
const raftNode = RaftNode.initialize(mqttClient, uuid);

// Set the logging function
raftNode.logFunction = console.log;

// Start the node
raftNode.start();

MQTT Client Configuration

For detailed configuration options and parameters for the MQTTClient, please refer to the official node-mqtt-client documentation.

Configuration Parameters for RaftNode

| Parameter | Type | Description | Default | |-----------------------|------------|---------------------------------------------------------------------|----------------| | electionTimeout | number | The timeout duration in milliseconds for the election process. | 8000 | | heartbeatInterval | number | The interval in milliseconds between heartbeats sent by the leader. | 2000 | | metric | number | The value used as the node's metric for leader elections. Lower values are considered better. |

RaftNode Public Variables

presenceManager (Read-only)

Returns the instance of the NodePresenceManager associated with the node.

  • Returns:
    NodePresenceManager - The presence manager instance.
logFunction

Gets or sets the log function.

  • Get: Returns the current log function.
    • Returns: Function - The log function.
  • Set: Sets a new log function for logging messages.
    • Parameters: func (Function): The new log function.

metric

Gets or sets the metric value used in leader elections.

  • Get: Returns the current metric value.

    • Returns: number - The metric value.
  • Set: Sets a new metric value.

    • Parameters: value (number): The new metric value.
leaderMetric (Read-only)

Gets the leader's metric value.

  • Returns:
    number - The current leader metric.

RaftNode Public Methods

initialize(mqttClient, uuid)

Initializes a new RaftNode instance if it does not exist.

  • mqttClient (MQTTClient): The MQTT client instance.

  • uuid (string): The unique identifier for the node.

    • Returns:
      RaftNode - The instance of the RaftNode.
log(message)

Logs a message using the provided log function.

  • message (string): The message to log.
start()

Starts the Raft node and initializes its state.

isLeader()

Checks if the current node is the leader.

  • Returns:
    boolean - true if the node is a leader, otherwise false.

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

Authors

See also the list of contributors who participated in this project.

License

This project is licensed under the MIT License. See the LICENSE file for details.