node-cocona-net

0.1.1 • Public • Published

cocona-net

A basic microservices module based on Cherry and cote.


Features:

  • Scopes
  • IDs
  • Groups
  • Versions
  • Update triggers
  • Encrypted data transfer

Installation:

To install the module:

yarn add node-cocona-net

Cherry is required to use cocona-net. You can get started with a new Cherry project by using Cherry-CLI.


Configuration:

await cherry.registerModule("node-cocona-net")
await cherry.createModule("node-cocona-net")
await cherry.loadModule("node-cocona-net", {
    loggingEnabled: true,
    conf: {
        id: "2qm7f4", //Default: name of current microservice package.json
        version: "0.0.1", //Default: version of current microservice package.json
        scope: "main", //Required: Scope of the used network
        key: "htpm5ezst5m5itj6", //Required: Encryption/Decryption key
        autoUpdate: true, //Default: true, should only be changed if really needed
    }
})

Documentation:

  • async createResponder
let module = await cherry.getModule("node-cocona-net")
let result = await module.createResponder(name, id = false, group = false, ignoreVersion = false)

Creates a new cote responder with given name, id and group. Only responder/requester with the same id and group can communicate with each other (Defaults to service id). Can ignore versions in the network (Only scope and group used). Returns true if successful.


  • async onResponder
let module = await cherry.getModule("node-cocona-net")
let result = await module.onResponder(name, event, func)
 
Example:
let result = await module.onResponder("TestResponder", "test", (data, cb) => {
    if(data.test === true)
        cb(true)
    else
        cb(false)
})

Creates a new cote responder event handler with given name and event type. Func gets called on every event with data and callback to send result back. Returns true if successful.


  • async createRequester
let module = await cherry.getModule("node-cocona-net")
let result = await module.createRequester(name, id = false, group = false, ignoreVersion = false)

Creates a new cote requester with given name, id and group. Only responder/requester with the same id and group can communicate with each other (Defaults to service id). Can ignore versions in the network (Only scope and group used). Returns true if successful.


  • async sendRequest
let module = await cherry.getModule("node-cocona-net")
let result = await module.sendRequest(name, event, alive, data, cb)
 
Example:
let result = await module.sendRequest("TestRequester", "test", 5000, {test: true}, (data) => {
    console.log(data)
})

Sends a new cote request with given name, event type, timeout in milliseconds and data. Callback gets called with result. Returns true if successful.


  • async createPublisher
let module = await cherry.getModule("node-cocona-net")
let result = await module.createPublisher(name, id = false, group = false, ignoreVersion = false)

Creates a new cote publisher with given name, id and group. Only publisher/subscriber with the same id and group can communicate with each other (Defaults to service id). Can ignore versions in the network (Only scope and group used). Returns true if successful.


  • async sendBroadcast
let module = await cherry.getModule("node-cocona-net")
let result = await module.sendBroadcast(name, event, data)
 
Example:
let result = await module.sendBroadcast("TestPublisher", "test", {test: true})

Sends a new broadcast via cote publisher with given name, event type and data. Returns true if successful.


  • async createSubscriber
let module = await cherry.getModule("node-cocona-net")
let result = await module.createSubscriber(name, id = false, group = false, ignoreVersion = false)

Creates a new cote subscriber with given name, id and group. Only publisher/subscriber with the same id and group can communicate with each other (Defaults to service id). Can ignore versions in the network (Only scope and group used). Returns true if successful.


  • async onBroadcast
let module = await cherry.getModule("node-cocona-net")
let result = await module.onBroadcast(name, event, func)
 
Example:
let result = await module.onBroadcast("TestPublisher", "test", (data) => {
    console.log(data)
})

Creates a broadcast event handler via cote subsriver with given name and event type. Func gets called on every event with data. Returns true if successful.


  • async onUpdateEvent
let module = await cherry.getModule("node-cocona-net")
let result = await module.onUpdateEvent(func)
 
Example:
let result = await module.onUpdateEvent(() => {
    console.log("Update")
})

Creates an update event handler (Using service id; cocona-net updates are global). Func gets called on every update event. Returns true if successful.


  • async onIdle
let module = await cherry.getModule("node-cocona-net")
let result = await module.onIdle(func)
 
Example:
let result = await module.onIdle(() => {
    console.log("Idle")
})

Creates an idle event handler. Func gets called anytime the application is idle (No requests being processed). Returns true if successful.


Contribution:

To run tests (incomplete):

yarn test

To start a test environment:

yarn start

Readme

Keywords

none

Package Sidebar

Install

npm i node-cocona-net

Weekly Downloads

0

Version

0.1.1

License

MIT

Last publish

Collaborators

  • pneugebala