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 @@ -27,6 +27,10 @@ var timesLimit = require('async/timesLimit');
27
27
var Configuration = require ( './Configuration.js' ) ;
28
28
var semver = require ( 'semver' ) ;
29
29
30
+ const http = require ( 'http' ) ;
31
+ const { setupMaster } = require ( '@socket.io/sticky' ) ;
32
+ const { setupPrimary } = require ( '@socket.io/cluster-adapter' ) ;
33
+
30
34
/**
31
35
* Override cluster module configuration
32
36
*/
@@ -39,7 +43,8 @@ if (semver.lt(process.version, '10.0.0')) {
39
43
else {
40
44
cluster . setupMaster ( {
41
45
windowsHide : true ,
42
- exec : path . resolve ( path . dirname ( module . filename ) , 'ProcessContainer.js' )
46
+ exec : path . resolve ( path . dirname ( module . filename ) , 'ProcessContainer.js' ) ,
47
+ serialization : 'advanced' , // for packets containing buffers (https://nodejs.org/api/child_process.html#child_process_advanced_serialization)
43
48
} ) ;
44
49
}
45
50
@@ -82,6 +87,16 @@ God.init = function() {
82
87
setTimeout ( function ( ) {
83
88
God . Worker . start ( )
84
89
} , 500 )
90
+
91
+ const httpServer = http . createServer ( ) ;
92
+
93
+ setupMaster ( httpServer , {
94
+ loadBalancingMethod : 'least-connection' ,
95
+ } ) ;
96
+
97
+ setupPrimary ( ) ;
98
+
99
+ httpServer . listen ( process . env . PM2_PORT || 8080 ) ;
85
100
}
86
101
87
102
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.1.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