Skip to content
This repository has been archived by the owner on May 7, 2022. It is now read-only.

Ridermansb/mqtt-server-fp-style

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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