Replies: 1 comment
-
I would create something like a Note the tricky part here might be how you handle multiple connections from the same channel and removing clients from the map once they disconnect. |
Beta Was this translation helpful? Give feedback.
-
Summary
I'm a bit of a noob to rust and axum specifically and struggling to determine what's the best approach for my need.
My app is more or less a notification system. I want to send messages/events from a server to client. There will be times when the message needs to go to various clients or a single client depending on the event. Communication needs only to be one way from server to client so SSE seems to be the right fit.
I've been researching and am a bit confused on the "recommended" solution for this task. Much of the information I'm finding seem to point at using tokio::sync::broadcast and I've been able to put a working sample together using broadcast but my confusion or question becomes how do I send a message/event to just a single client. Further research seems to point to using tokio::sync::mpsc but I'm not able to find many examples of how to use this and the ones I do find, seem to suggest using broadcast instead.
I'm hoping someone can give me some suggestions on how to approach this and if you know of any sample code to point me in the right direction it would be very much appreciated.
Thanks in advance.
axum version
0.7.5
Beta Was this translation helpful? Give feedback.
All reactions