kifli

1.1.0 • Public • Published

kifli

Build Status Coverage Status npm version dependencies Status devDependencies Status

nano library to handle messages sent throught MQTT protocol. It wraps the mqtt.js module

Motivation

I wanted to create a very lightweight message handler on the top of MQTT. The main goal of this module is to use the power of the MQTT pub/sub model to create sort of chainable nanoservices without too much boilerplate.

Highly inspired by zeit/micro and developit.

Usage

  • npm install --save kifli
  • add the following script to your package.json
{
  "scripts": {
    "start": "kifli handler.js --broker mqtt://localhost:1883 --topic '/sum' "
  }
}
  • create a handler.js file
// handler.js
 
module.exports = ({ publish }) => async ({ topic, payload }) => {
  await publish('/sum/result', {result: payload.a + payload.b});
};
 
// the handler is automatically subscribed to the /sum topic
// assume that this topic always recevies two numbers (a and b) which shall be sumed
// the handler does its job and publish the result to a /sum/result topic
// imagine you have a handler which is listening to the /sum/result topic...
 

Package Sidebar

Install

npm i kifli

Weekly Downloads

1

Version

1.1.0

License

MIT

Last publish

Collaborators

  • balazs4