socket.io-redis-adapter
socket.io-redis-adapter copied to clipboard
serverSideEmit with ack question
I have multiple nodejs services, all of which are connected to the same socket.io-redis-adapter. I want to be able to send messages between these services with acknowledgement using serverSideEmit. My problem is the next scenario: Let's say I have 3 nodejs services - s1, s2, s3.
Both s1 and s2 are sending the same message m1 to a namespace which is also called m1 (for the sake of simplicity): io.of(/m1).serverSideEmit(m1, data, (error, responses) => {})
I want only s3 to subscribe to m1 namespace.
The problem with the current implementation, is that after s1 sends m1, and s2 sends m1, we now we have 3 subscribers to m1 namespace (s1, s2, s3), but only s3 is set to ack this message:
io.of(/m1).on(m1, (data, callback) => {})
any service that sends m1 (either s1 or s2) is waiting for 2 responses (since it has 3 subscribers), but it only gets 1 response (from s3), and keeps throwing errors due to timeout
How can I work around this issue?
If there was an option to override numsub (since I know how many responses I should get) with a param given to serverSideEmit then it would solve this issue
Well, can't you just... ignore the timeout? Or send an empty reply from the other services?
I could, but it's kind of weird that the sender needs to reply to its own messages. Anyway, I have built a different system for it based on redis streams. I wanted to use it as an IPC replacement but I have already managed to achieve it. Thanks
Closed due to inactivity, please reopen if needed.