Synchronize service events between application instances using Redis or MongoDB publish/subscribe
When running multiple instances of your Feathers application (e.g. on several Heroku Dynos), service events (
removed) do not get propagated to other instances. feathers-sync uses MongoDB publish/subscribe via mubsub or Redis via redis to propagate all events to all application instances.
This allows to scale real-time websocket connections to any number of clients.
The application initialized in the following example will use the local
feathers-sync database and
sync collection and share service events with every other instance connected to the same database:
var feathers = ;var sync = ;var app = ;app;app;
mongodb://localhost:27017/events) or database object
Additionally you can pass the original sync options:
redis://localhost:6379) or database object
When listening to service events with this, all events are going to get propagated to all clients. This means, that your event listeners should not perform any actions that change the global state (e.g. write something into the database) because every client will perform the same action.
Instead, event listeners should only be used to update the local state (e.g. a local cache) and send real-time updates to all connected clients, e.g. all browsers listening to websocket events.
If you need to perform actions, for example setting up a first blog post after a new user has been created add it to the service method itself (which will only run on its own instance) or use feather-hooks after hooks.
Copyright (c) 2015 David Luecke
Licensed under the MIT license.