ipc-healthcheck

1.3.0 • Public • Published

IPC-HealthCheck

Health Check server and client for nodejs applications using ipc via unix and windows sockets.

Version NodeJS Version GitHub license open issues


Contents

  1. Install
  2. Server
    1. Create Server
    2. Server Methods
    3. Events
  3. Client
    1. Create Client
    2. Client Methods
  4. Examples

Install

NodeJS version >=14 is required for this module.

Install via npm:

npm install ipc-healthcheck


Server

Include the server

const HealthcheckServer = require('ipc-healthcheck/healthcheck-server');

Create Server

Creating a new server object Parameter:

  • namespace: String - Health check server name clients can connect to.
  • respondTime : int - Time in ms the server gives the client to respond
  • intervalTime : int - Time in ms the server waits between every request
  • silent : boolean - Turns debug messages on or off. true = no debug messages
const server = new HealthcheckServer(namespace, respondTime, intervalTime, silent);

Server Methods

The server has the following methods:

startServer()

Start the socket server and starts sending requests to all connected clients. (void)

server.startServer()

stopServer()

Stops sending requests and stops the server. (void)

server.stopServer()

Events

The server does fire the following events:

serviceRegistered

A new client connected and registered to the Server. Healthcheck messages are now sent to this client.

Parameters

  • service: Object - Service object
    • name: String - Name with which the service is registered
    • id: String - ID the Server has given this service
server.on('serviceRegistered', (service) => {
    //do stuff
});

serviceCrashed

A client that registered at the Server did not answer the last 3 health check requests and might be crashed.

Parameters:

  • service: Object - Service object
    • name: String - Name with which the service is registered
    • id: String - ID the Server has given this service
    • lastrespond : Date - Time the service did the last respond to a request.
server.on('serviceCrashed', (service) => {
    //do suff
});

serviceNotify

This event triggers, when a client sends an message to the server.

Parameters:

  • msg : String - Message the client send to the Server
  • service: Object - Service object
    • name: String - Name with which the service is registered
    • id: String - ID the Server has given this service
    • lastrespond : Date - Time the service did the last respond to a request.
server.on('serviceNotify', (msg, service) => {
    //do stuff 
});

serviceDetached

A client that was connected to the server called the detach function and disconnected. This client will not receive any healthcheck messages.

Parameters:

  • service: Object - Service object
    • name: String - Name with which the service is registered
    • id: String - ID the Server has given this service
    • lastrespond : Date - Time the service did the last respond to a request.
server.on('serviceDetached', (service) => {
    //do stuff 
});

Client

Include the client

const HealthcheckClient = require('ipc-healthcheck/healthcheck-client');

Create Client

Creating a new client object

Parameter:

  • namespace: String - Health check server name the client should connect to
  • serviceID : _String - The name with which the client registers with the server
  • silent : boolean - Turns debug messages on or off. true = no debug messages
const healthcheckclient = new HealthcheckClient(namespace,serviceID,silent);

Client Methods

The client has the following methods:

startListening()

Client connect to the server and starts listening to health check requests. (void)

client.startListening();

notify()

Sends a message to the server (void)

Parameters:

  • msg : String - The message that should be send to the server
client.notify(msg);

detach()

Tell the server to not get any requests anymore and disconnect. (void)

client.detach();

Examples

You can find examples in this repo.


Package Sidebar

Install

npm i ipc-healthcheck

Weekly Downloads

0

Version

1.3.0

License

MIT

Unpacked Size

13.5 kB

Total Files

5

Last publish

Collaborators

  • bielefeldj