[FEATURE REQUEST] adapters support for scalability
Like socketio or signalr, they provide serval adapters such as redis. Hope neffos could provide the adapter interface. let users could add their own implemention; And It would be great for builtin support serval great pubsub system like redis and nats
Thanks again for the great library.
Hello @syklevin, neffos already allow users to add their own implementations or wrap an existing one, see the Upgrader and Dialer interfaces that target the Socket interface (I think that is what you are refer to), read wiki at: https://github.com/kataras/neffos/wiki/Upgraders-and-dialers
Tell me if that helped, and if not, please write down how you imagine it to use/API, with go code.
I thank YOU for your support!
thanks for the docs, let me read it deeply and try to make a custom Upgrader.
@syklevin Sorry, the Upgraders and Dialers is not the place for that type of implementation (it can be done through it but it requires more boilerplate code at this case). I have to ask you, signalr can keep messages that's why redis is important there on production and to scale out but neffos does not percist messages so there is no data stored in the server-side except the websocket connections and its information like connected namespaces and joined rooms. At the other side, for scaling it may be useful but are we sure is for the best or real need to adapt redis pub sub on neffos as a built-in feature? Because I think you can handle it outside of neffos, inside your app, and just call the specific events based on the connection ID from a redis SUBSCRIBE and do redis PUBLISH from inside neffos events.
Give me some days for R&D and thinking more about the necessity of implement that as built-in package (which will require an external dependency of the redigo library, which is heavy and I really want to keep neffos clean of extra external dependencies) or as a different optional package/repository.
Hey @syklevin , It didn't took long, 1 day asleep and it's ready. It works with redis clusters too (signalR does not). I didn't use the redigo library because it's heavy enough and I wanted other code style for performance boost and subscribe whenever is required, so I used the radix one as I did with iris redis session database for v11.2 - it is not popular like redigo or redis-go but as far as I made my research, he seems a passionate guy and good coder*
Example: https://github.com/kataras/neffos/tree/master/_examples/scale-out
Redis
import "github.com/kataras/neffos/stackexchange/redis"
// [server := neffos.New...]
exc, err := redis.NewStackExchange(redis.Config{}, "MyChatApp")
if err != nil {
// [...]
}
server.UseStackExchange(exc)
Nats
import "github.com/kataras/neffos/stackexchange/nats"
// [server := neffos.New...]
exc, err := nats.NewStackExchange(":4222" /*, [other optional args here...]*/ )
if err != nil {
// [...]
}
server.UseStackExchange(exc)
Made with:
- https://github.com/kataras/neffos/commit/4de9b6608fc914beceeb7eedbd2ab1680635b094
- https://github.com/kataras/neffos/commit/860a59d280a8e5cf08530ba24b8be6c1d7da0f39
- https://github.com/kataras/neffos/commit/71e5a09d0259bb81a596689aa6b465e377311c26
Please test it out and tell me if I missed something out or if that was exactly what you were looking for, thanks again!
WOW! That is exactly what i looking for. can't wait to try it out and get back to you.