A Seneca.js transport plugin that provides various client-side load balancing strategies, and enables dynamic reconfiguration of client message routing.
This module is a plugin for the Seneca framework. It provides a transport client that load balances outbound messages on a per-pattern basis.
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.
Supports Seneca versions 3.x and above.
npm install seneca-balance-client
And in your code:
// run twice:// $ node server.js 47000 --seneca.log=type:act// $ node server.js 47001 --seneca.log=type:act
// $ node client.js --seneca.log=type:act
The client will balance requests over both servers using
round-robin. As there is no pin in the
.client configuration, this
will apply to all non-local actions. Add a pin to restrict the
action patterns to which this applies - make sure to use the same
pin on both client and server to avoid ambiguity.
The plugin provides two balancing models:
consume: messages are sent to individual targets, using a round-robin approach
observe: messages are duplicated and sent to all targets
You specify the model using the plugin option
var Seneca =var s0 =var s1 =var c0 =s0
You can also provide your own balancing model by providing a function
(seneca, msg, targetstate, done) as the value of the
targetstate object provides you with the list of currently
available targets. Review the internal implementations of the
observeModel and the
for a starting point to write your own model.
The Senecajs org encourages open participation. If you feel you can help in any way, be it with documentation, examples, extra testing, or new features please get in touch.
To run tests, simply use npm:
npm run test
Copyright (c) 2010-2016, Richard Rodger and other contributors. Licensed under MIT.