-
-
Notifications
You must be signed in to change notification settings - Fork 602
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Detach server from node #186
Conversation
At moment after this refactoring it's possible to start Centrifugo inside Go app with only raw Websocket endpoint in this way: package main
import (
"net/http"
"github.com/centrifugal/centrifugo/libcentrifugo/channel"
"github.com/centrifugal/centrifugo/libcentrifugo/engine/enginememory"
"github.com/centrifugal/centrifugo/libcentrifugo/node"
"github.com/centrifugal/centrifugo/libcentrifugo/server"
)
func main() {
nodeConfig := node.DefaultConfig
nodeConfig.Secret = "secret"
nodeConfig.Namespaces = []channel.Namespace{
channel.Namespace{
Name: "public",
Options: channel.Options{
Publish: true,
Presence: true,
JoinLeave: true,
},
},
}
n := node.New(nodeConfig)
e, err := enginememory.New(n, &enginememory.Config{})
if err != nil {
panic(err)
}
if err := n.Run(e); err != nil {
panic(err)
}
serverConfig := &server.Config{}
s, err := server.New(n, serverConfig)
if err != nil {
panic(err)
}
opts := server.MuxOptions{
Prefix: "", // can be sth like "/centrifugo" in theory
HandlerFlags: server.HandlerRawWS,
}
mux := server.ServeMux(s, opts)
http.Handle("/", mux)
if err := http.ListenAndServe(":8000", nil); err != nil {
panic(err)
}
} So theoretically this can be a starting point to use Centrifugo as library - but this is out of scope of this pull request. |
…h_server_from_node
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow this is a lot of code changes to review.
Overall I think this is a great idea - I never really saw the value in the mediator and agree that making Centrifugo into a lib is a bigger design problem than just a few hooks here and there.
I like removing a lot of code! I've not yet had a chance to look through this really closely. I'm happy if it's been well tested to accept, but it comes with a big pinch of salt that I've not really looked closely :)
If you'd really like a super thorough review @FZambia, I can try to find some more time later int he week to try and get my head around this more.
@banks Paul - thanks for looking, it was important to hear that you agree with main idea. Then I suppose I'll merge this at some point - but any comment before that can help of course. |
In version 1.6.0 we introduced registration of custom server implementation using plugin-like system but as time goes I don't see any benefit in this design - this only makes code more complicated. In this pr I removed support for registering many servers and what is good now is that
Node
now does not know anything about server. I think this is a right step to isolate components from each other.Also I removed Mediator interface - I still hope that one day in future Centrifugo can be used as library but it should probably be designed from scratch - for now Mediator is just extra unused code.
This pr introduces breaking changes in internal packages API but no breaking changes for Centrifugo server users - everything should work the same way.
Also some other minor changes also included - various code quality improvements.