Ridermansb / mqtt-server-fp-style

Micro MQTT server in Functional Programming style

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Example use FP to handle MQTT request

An processor process the request using

const resolve = R.cond([
    [ CONDITION, EXECUTER ]
]);

The CONDITION should return true or false indicating if EXECUTER should be execute or not.

The EXECUTER should return a valid MQTT package to be publish or undefined/false if nothing to be do.

const publishIfConditionalResolved = R.pipe(
  resolve,
  R.when(R.identity, publish),
);

CONDITION

To validate the request we recommend ...

 function CONDITION(pack) {
     return /^myReq$/.test(pack.topic)
 }

Tip: use JSON Schema to validate the payload

EXECUTER

Should return a valid package..

function EXECUTER(pack) {
    pack.payload = new Buffer.from(JSON.stringify({hello:'word'}))
    return pack 
}

Get Starter

  • npm install
  • npm start

About

Micro MQTT server in Functional Programming style

License:GNU General Public License v3.0


Languages

Language:JavaScript 100.0%