Mesh your Seneca.js microservices
- Lead Maintainer: Richard Rodger
- Sponsor: nearForm
This plugin allows you to wire up seneca services using automatic meshing. Uses the SWIM gossip algorithm for automatic configuration of the microservice network.
If you're using this module, and need help, you can:
- Post a github issue,
- Tweet to @senecajs,
- Ask on the Gitter.
If you are new to Seneca in general, please take a look at senecajs.org. We have everything from tutorials to sample apps to help get you up and running quickly.
To install, simply use npm
npm install seneca-balance-client
npm install seneca-mesh
The seneca-mesh plugin depends on the seneca-balance-client plugin.
And in your code:
require('seneca')()
.use('mesh', { ... options ... })
To run tests, simply use npm:
npm run test
Demonstrates connecting two services together using a base node. Base nodes are used so that other nodes have a known reference point to join the network. They are only required for the inital mesh, once the mesh is live, it becomes redundant.
require('seneca')()
.use('mesh',{base:true})
// start first!
// $ node base.js
require('seneca')()
.add( 'foo:1', function (msg, done) {
done( null, {x:1,v:100+msg.v} )
})
// this service handles foo:1 messages
.use('mesh', { auto:true, pin:'foo:1' })
.ready( function () {
var seneca = this
setInterval( function() {
// use bar:1, even though location of
// service-bar is not configured!
seneca.act('bar:1,v:2', console.log)
}, 3000 )
})
// $ node service-foo.js
require('seneca')()
.add( 'bar:1', function (msg, done) {
done( null, {x:1,v:100+msg.v} )
})
// this service handles bar:1 messages
.use('mesh', { auto:true, pin:'bar:1' })
.ready( function () {
var seneca = this
setInterval( function() {
// use foo:1, even though location of
// service-foo is not configured!
seneca.act('foo:1,v:2', console.log)
}, 3000 )
})
// $ node service-bar.js
The foo and bar services call each other, but neither requires configuration information!
The example below shows you how to use consume and observe models on individual pins. By default patterns are created in consume mode. If observe mode is used all action handlers are called for that pattern.
require('seneca')
.use('my-plugin')
.use('mesh', {
auto: true,
listen: [
{pin: 'role:search,cmd:upsert', model: 'consume'},
{pin: 'role:search,cmd:search', model: 'consume'},
{pin: 'role:info,info:updated', model: 'observe'}
]
})
You can review the source code of these example projects to see seneca-mesh in action:
The [Seneca.js org][] encourages open and safe participation.
- [Code of Conduct][]
If you feel you can help in any way, be it with documentation, examples, extra testing, or new features please get in touch.
Copyright (c) 2015, Richard Rodger and other contributors. Licensed under MIT.