SocketCluster / asyngular

Highly scalable realtime framework compatible with SocketCluster
https://asyngular.io/
MIT License
77 stars 5 forks source link

Publish message to all workers and them forward this message to their connected sockets #9

Open JCMais opened 4 years ago

JCMais commented 4 years ago

@jondubois first, thanks for the amazing library!

My use case is the following one, I have N workers, with X sockets connected to them, I want to publish an event to all workers, which will then emit an event to all connected sockets (via transmit). This is needed because someone connected to one of the workers, can modify some state that needs to be updated on everyone connected to the server, however, this change must pass on the server first (so I cannot simply publish to some channel every client subscribes to). My idea was to simply publish to some channel using agServer.exchange.transmitPublish, which every worker listens to via agServer.exchange.subscribe, then each one would consume this event and forward it to the connected sockets, like this:

  // ...
  for (const socket of Object.values(agServer.clients)) {
    socket.transmit('some-receiver', someData)
  }
  // ...

But this is not working, only the worker that published the message receives it. What I'm doing wrong? I recall this workflow worked with Socketcluster.

All this is using the latest version deployed directly to Kubernetes with 1 agc state, 1 broker and 3 workers.

jondubois commented 4 years ago

@JCMais Sorry for the delay in response. Could this issue have been caused by: https://github.com/SocketCluster/asyngular/commit/b5213a8a0de3d4a392642a21da3e9912b7428bdf

Fixed in November.