Websockets - manage active subscriber's sessions?

Hey everyone,

First time using this forum so apologies if this is not the correct format for asking this.

I am trying to replicate a publish to many subscribers pattern where a user subscribes to a websocket route with a parameter and the server keeps track of all users subscribed with that specific parameter. Whenever there is an update at route X, the app is signalled to check if there are any subscribers with event X (X = paramater users subscribe with) and then sends them all a message or data. The client app is allowed to unsubscribe from certain topics and resubscribe to another one during the whole flow though.

I haven’t really implemented something like this before so apologies if I am not understanding or didn’t do my research correctly.

Any help regarding starting steps or general implementation of the solution will be greatly helpful.

Thanks

This is actually a fairly common pattern for chat applications. There’s really not any advice I can give you without any code to work with or see what you’re doing now, but I would recommend you search for ‘websocket chat applications’ or something similar to help with your research.

Thank you @sjsadowski , I was able to implement the solution I needed after following some architectural patterns from several articles after searching about that.

1 Like

@hasanjafri Not sure if this is still relevant…

As @sjsadowski said, this is a VERY common question. So much so that one of these days I will get around to adding it here: Table of Contents | Sanic Framework

But, I have created a Gist a while ago here: https://gist.github.com/ahopkins/9816b39aedb2d409ef8d1b85f62e8bec that sounds like it is in the right direction. I have a newer version of that snippet that I can provide if you’d like. Before the next release I hope to have it on the docs.

Hey @ahopkins

Thanks for your reply, that is definitely very interesting and I will check it out. I would appreciate if you could share the newer snippet too, this will be great to refer back to. Very excited for the next release btw!

Here is the latest version

1 Like

@ahopkins Thanks a lot! This will help big time!

1 Like