Skip to content
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

Merged
merged 17 commits into from
Jul 13, 2017
Merged

Detach server from node #186

merged 17 commits into from
Jul 13, 2017

Conversation

FZambia
Copy link
Member

@FZambia FZambia commented Jun 23, 2017

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.

@FZambia
Copy link
Member Author

FZambia commented Jun 24, 2017

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.

@FZambia FZambia requested a review from banks June 24, 2017 09:39
Copy link
Member

@banks banks left a 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.

@FZambia
Copy link
Member Author

FZambia commented Jul 12, 2017

@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.

@FZambia FZambia merged commit 23cddc6 into master Jul 13, 2017
@FZambia FZambia deleted the detach_server_from_node branch July 3, 2018 13:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants