adonis-websocket
adonis-websocket copied to clipboard
PM2 support
Proposed changes
Extract serializing messages for ClusterHop to serializer and add conditional implementation when process is managed by pm2 so messages can be handled by message bus in PM2 module.
See issue #58 for detailed explanation.
Types of changes
What types of changes does your code introduce?
- [x] Bugfix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
Checklist
- [x] I have read the CONTRIBUTING doc
- [x] Lint and unit tests pass locally with my changes
- [ ] I have added tests that prove my fix is effective or that my feature works.
- [ ] I have added necessary documentation (if appropriate)
Further comments
Recieved and sent events need to have type when using PM2. I chose the name adonis:hop
. This event type needs to be used when listening and emitting messages on PM2 message bus. I wrote a simple PM2 module, which can be used for broadcasting messages. You can install it as follows:
pm2 install ruby184/pm2-adonis
Also when I was testing if everything is working I found that Channel.clusterBroadcast
is calling non exisitng method Channel.broadcast
, which was renamed to Channel.broadcastPayload
in commit https://github.com/adonisjs/adonis-websocket/commit/5a3464ca2eb4cf20724657745bba1c11e3cf2ebb. So I fixed it in this PR.
There is one more bug according to broadcasting to workers. When you use Socket.emitTo
method, event is sent only to given IDs on current worker, but then broacasted and sent to ALL sockets for topic on other workers. I will send another PR to fix this issue.
Coverage decreased (-0.4%) to 93.333% when pulling bbc4af23ccdeac0a1d1cce55ddd3ba3bc51d128c on Ruby184:pm2-support into 27143fdf833b06d565330b2f83c1ce0c46a11f0d on adonisjs:develop.
it's been over a year. we are using PM2 on production and need to use websockets. how is this pull request? how can I use pm2 cluster mode?
Any updates on this? Would really like to see PM2 cluster support.
2021 and no updates?