hmq
v1.0.4
Published
Hypercore based queue module
Downloads
2
Readme
Hmq
Hmq is a Hyperbee based rpc. A node using hmq can be controller by adding one or more Hyperbee controllers.
Example
Controlled node
const { Hmq } = require('hmq')
const ram = require('random-access-memory')
const controller = process.argv[2].split(',')
const callback = (data) => {
if(data.key === "say-hi"){
console.log(data.controller, "says hi!")
}
}
const rpc = new Hmq(ram, {callback : callback})
await rpc.init()
await rpc.add(controller)
Controller
const { HmqController } = require('hmq')
const controller = new HmqController()
await controller.init()
console.log(controller.core.key.toString('hex'))
setInterval(async () => await controller.send('say-hi'), 2000)
API
const hmq = new Hmq(storage, opts = {})
- storage: corestore storage
- opts.core: hypercore public key of controllers Hyperbee. Can use this to replicate a controlled node.
- opts.callback: function with signature (key, value, seq) => result. This is the callback function for every new entry in any controller. Result will be store in another Hyperbee with key controller.key!key!value!seq.
hmq.init()
Setup controllers and start watching.
hmq.add(key)
Add new controller by Hypercore public key.
hmq.on('update', entry)
Event emmited when new controller entry found.
hmq.on('controller', key)
Event emmited when new controller added.