File tree Expand file tree Collapse file tree 3 files changed +23
-2
lines changed Expand file tree Collapse file tree 3 files changed +23
-2
lines changed Original file line number Diff line number Diff line change @@ -26,12 +26,17 @@ var cst = require('../constants.js');
26
26
var timesLimit = require ( 'async/timesLimit' ) ;
27
27
var Configuration = require ( './Configuration.js' ) ;
28
28
29
+ const http = require ( 'http' ) ;
30
+ const { setupMaster } = require ( '@socket.io/sticky' ) ;
31
+ const { setupPrimary } = require ( '@socket.io/cluster-adapter' ) ;
32
+
29
33
/**
30
34
* Override cluster module configuration
31
35
*/
32
36
cluster . setupMaster ( {
33
37
windowsHide : true ,
34
- exec : path . resolve ( path . dirname ( module . filename ) , 'ProcessContainer.js' )
38
+ exec : path . resolve ( path . dirname ( module . filename ) , 'ProcessContainer.js' ) ,
39
+ serialization : 'advanced' , // for packets containing buffers (https://nodejs.org/api/child_process.html#child_process_advanced_serialization)
35
40
} ) ;
36
41
37
42
/**
@@ -73,6 +78,16 @@ God.init = function() {
73
78
setTimeout ( function ( ) {
74
79
God . Worker . start ( )
75
80
} , 500 )
81
+
82
+ const httpServer = http . createServer ( ) ;
83
+
84
+ setupMaster ( httpServer , {
85
+ loadBalancingMethod : 'least-connection' ,
86
+ } ) ;
87
+
88
+ setupPrimary ( ) ;
89
+
90
+ httpServer . listen ( process . env . PM2_PORT || 8080 ) ;
76
91
}
77
92
78
93
God . writeExitSeparator = function ( pm2_env , code , signal ) {
Original file line number Diff line number Diff line change @@ -57,6 +57,10 @@ module.exports = function ClusterMode(God) {
57
57
* Broadcast message to God
58
58
*/
59
59
clu . on ( 'message' , function cluMessage ( msg ) {
60
+ if ( msg && msg . source === '_sio_adapter' ) {
61
+ // ignore messages from the @socket .io/cluster-adapter (https://github.com/socketio/socket.io-cluster-adapter)
62
+ return ;
63
+ }
60
64
/*********************************
61
65
* If you edit this function
62
66
* Do the same in ForkMode.js !
Original file line number Diff line number Diff line change 1
1
{
2
- "name" : " pm2" ,
2
+ "name" : " @socket.io/ pm2" ,
3
3
"preferGlobal" : true ,
4
4
"version" : " 5.3.0" ,
5
5
"engines" : {
170
170
"@pm2/io" : " ~5.0.0" ,
171
171
"@pm2/js-api" : " ~0.6.7" ,
172
172
"@pm2/pm2-version-check" : " latest" ,
173
+ "@socket.io/cluster-adapter" : " ^0.1.0" ,
174
+ "@socket.io/sticky" : " ^1.0.0" ,
173
175
"async" : " ~3.2.0" ,
174
176
"blessed" : " 0.1.81" ,
175
177
"chalk" : " 3.0.0" ,
You can’t perform that action at this time.
0 commit comments