Metroplex a Redis based spark/connection registry for Primus.
Metroplex is released in the npm registry and can therefor be installed using:
npm install --save metroplex
Once you've installed the module you need to tell Primus to use the plugin which
is done using the
'use strict';var http =Primus =primus = http transformer: 'sockjs' ;primus;
In the example above you've seen how to add the plugin to your Primus server but not how to configure it. We have various of options that can be configured in this plugin:
alivekey in Redis. This time is subtracted from the set
intervalso we update the key BEFORE it expires. Defaults to
These options should be provided in the options object of the Primus server:
primus = httptransformer: 'sockjs'namespace: 'metroplex'redis:;primus;
The orchestration is all done using the
metroplex library which is bundled in
this plugin. The Metroplex instance is exposed on the
Primus instance when you
use this plugin:
The following public methods are available.
List all the servers in our current registry.
Get the server for the given spark id. It does not check if the spark is hosted on the current server. That's up to the developer to implement.
Get the servers for each id in the given
sparks array. It will return an
object and just like
metroplex.spark it does not check if the spark is hosted
on the current server.
If you load the
metroplex, you can use some additional convenience methods.
These methods are added to the
Broadcast a message to all sparks in the cluster.
forward.sparks(ids, msg, fn)
Send a message to a set of sparks in the cluster.
forward.spark(id, msg, fn)
Send a message to a single spark in the cluster.