mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-08 06:55:46 +01:00
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:
committed by
Barış Soner Uşaklı
parent
148fc96a3a
commit
c1e98eefa7
@@ -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')) {
|
||||
|
||||
Reference in New Issue
Block a user