Allow single-host clusters to not send pubsub and socket.io messages through the database. (#6659)

* Allow single-host clusters to not send pubsub and socket.io messages through the database.

* Fix lint errors.
This commit is contained in:
Ben Lubar
2018-07-23 11:21:36 -05:00
committed by Barış Soner Uşaklı
parent 148fc96a3a
commit c1e98eefa7
4 changed files with 32 additions and 2 deletions

View File

@@ -1,5 +1,6 @@
'use strict';
var EventEmitter = require('events');
var nconf = require('nconf');
var real;
@@ -12,9 +13,22 @@ function get() {
var pubsub;
if (nconf.get('isCluster') === 'false') {
var EventEmitter = require('events');
pubsub = new EventEmitter();
pubsub.publish = pubsub.emit.bind(pubsub);
} else if (nconf.get('singleHostCluster')) {
pubsub = new EventEmitter();
pubsub.publish = function (event, data) {
process.send({
action: 'pubsub',
event: event,
data: data,
});
};
process.on('message', function (message) {
if (message && typeof message === 'object' && message.action === 'pubsub') {
pubsub.emit(message.event, message.data);
}
});
} else if (nconf.get('redis')) {
pubsub = require('./database/redis/pubsub');
} else if (nconf.get('mongo')) {