amberframework / amber

A Crystal web framework that makes building applications fast, simple, and enjoyable. Get started with quick prototyping, less bugs, and blazing fast performance.
https://amberframework.org
MIT License
2.57k stars 205 forks source link

WebSocket in cluster mode #1274

Closed vincar closed 2 years ago

vincar commented 2 years ago

Description

I see ClientSocket.broadcast is just call channel.rebroadcast!

protected def rebroadcast!(message)
    subscribers = ClientSockets.get_subscribers_for_topic(message["topic"])
    subscribers.each_value(&.socket.send(message.to_json))
end

when it runs in cluster mode, the socket in other process which subscribe the same topic can not receive the message

crimson-knight commented 2 years ago

@vincar I think that makes sense, especially if all running app instances are on the same machine and using the same port. Only a single instance is going to receive the message.

Are you trying to use the ClientSocket as a pub/sub system like RabbitMQ or Kafka?