a lib for nodejs to create multy process and still have a good feeling
npm install worker-boss
- convenien way to create multy process
- less cost to send message to another process
the first process must use this method to tell what the cluster id is
const boss = require("worker-boss")
await boss.init(1)
creat a new worker that is running in another process
let id = await boss.new_worker("./example/test_service_step.js",1,2,3)
do a remote invoke to the target_worker,and the target worker must regist a callback
boss.invoke_worker(id, "test_123")
do a rpc to the target_worker,and the target worker must regist a callback
let ret = await boss.call_worker(id, "test_123", false)
console.log(`get result:${ret}`)
regist invoke callback
boss.on_invoke(function (func_name, ...args)
{
console.log(`get call:${func_name}(${args})`)
return args
})
regist a rpc callback
boss.on_call(function (func_name, ...args)
{
console.log(`get call:${func_name}(${args})`)
return args
})