squiddy
v0.2.7
Published
ipc network for microservices
Downloads
22
Maintainers
Readme
ipc network for microservices on local machine (unix sockets)
Install
$ npm install squiddy
Usage
run the hub process
$ node node_modules/squiddy/hub.js
instantiate a link in a process to make it a client
const ServiceLink = require('squiddy').link
const link = new ServiceLink("this-service")
link.connect()
.then(() => link.waitFor("another-service"))
.then(() => {
console.log("found another-service")
})
create a request method
link.addRequestMethod("my-request-method", executeFunction)
(function can syncronous or asyncronous)
call a request method
link.request("another-service", "my-request-method")
.then(response => {
})
or, with arguments:
link.request("another-service", {
method: "my-request-method",
args: [...myArgs]
})
create a channel
link.createChannel("myChannel", onSubscribeFunction)
broadcast from a channel
link.broadcast("myChannel", channelMessage, specificSubscriber)
// if specificSubscriber is undefined then this broadcasts to all subscribers
subscribe to a channel
link.subscribe("another-service", "myChannel", callback)
or, for multiple actions for a subscription:
link.onChannelMessage("another-service", "myChannel", callback1)
link.onChannelMessage("another-service", "myChannel", callback2)
License
MIT