Skip to content

pdspicer/seneca-mesh

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Seneca

Mesh your Seneca.js microservices

seneca-mesh

npm version Build Status Gitter

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:

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.

Install

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 ... })

Test

To run tests, simply use npm:

npm run test

Example One

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.

base.js

require('seneca')()
  .use('mesh',{base:true})

// start first!
// $ node base.js

service-foo.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

service-bar.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!

Example Two

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'}
    ]
  })

Further examples

You can review the source code of these example projects to see seneca-mesh in action:

Contributing

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.

License

Copyright (c) 2015, Richard Rodger and other contributors. Licensed under MIT.

About

seneca-mesh

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%