Comments (4)
The channels are designed to have more then just 1 subscriber (you can have only one subscriber as well). It does not matter on which worker will the channel end up as pub sub system is designed to be able to send message from any server to the right channel.
One way to listen on the publish event on the server is onPublish
event documentation is in here. However i am not sure it will work out well as publish system will not process with message if no client on that worker subscribed to that channel. (i need more information about the app and how you plan it to work)
Second way is to use onMessageFromWorker
from the same documentation in here and standard 1on1 communication with client. For example:
function Worker() {
const wss = this.wss
const server = this.server
// listen on messages from workers
wss.setMiddleware('onMessageFromWorker', (message) => {
// execute any code on message form workers
})
// Listen on connections to websocket server
wss.on('connection', (socket) => {
socket.on('matchmaking', (message) => {
// send message to all workers NOTE: including itself
wss.publishToWorkers(message)
})
})
}
That is actually a good point you have provided, i will add functionality to subscribe workers to the channels (only with ability to listen on messages which are send through the channels)
from clusterws.
Yeah, I found the publishToWorkers while toying around with the problem. It works, but it feels like a dirty hack and its not very readable. I am glad this functionality is coming though 👍
from clusterws.
I have released new version 3.1.0 the functionality to listen on channels is added there. Check this for more info about it.
from clusterws.
Close issue as completed.
from clusterws.
Related Issues (20)
- Is it possible create different (non clone) processes? HOT 4
- Close/Stop/Kill the server HOT 1
- How to determine which process current code is running in. HOT 7
- Having interest in translate document to zh-CN HOT 7
- Plz add `upgradeReq` argument, let it back HOT 1
- Can I store a dictionary in memory accessed from each workers? HOT 4
- How to upload files? HOT 4
- Publish to channel but only to some users HOT 5
- Callback in verify connection middleware HOT 6
- ws / wss proxy with nginx HOT 7
- How to send msg by userid connection? HOT 1
- Del
- Websockets inside a cluster, ok in production? HOT 2
- Callback issue on verifyConnection middleware HOT 12
- benchmark & does it work on browser too ? HOT 2
- uws not compiled for node 7.2
- How to see the list of channels a client is subscribed to HOT 3
- Don't understand what .processMessage is for? HOT 5
- Middleware.onPublishIn ? HOT 1
- TypeError: this.options.logger.warning is not a function
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from clusterws.