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

Add FanOut proposal #166

Merged
merged 10 commits into from
Dec 20, 2019
Merged

Add FanOut proposal #166

merged 10 commits into from
Dec 20, 2019

Conversation

m110
Copy link
Member

@m110 m110 commented Nov 28, 2019

During development of ThreeDotsLabs/watermill-http#3 it occurred to me that we could abstract the "router" I created here, so this is a proposal of adding a FanOut component.

This is essentially a wrapper over GoChannel Pub/Sub that lets you send messages coming from upstream subscriber to any number of internal publishers. This might be useful if you need a lot of subscribers and don't want to create a separate subscription for each of them.

Keep in mind this is an early idea, so feedback is welcome. Docs and more tests are obviously missing.

I also considered another API for this, that will create its own router and will be started just like a router. Maybe both could be available.

message/router.go Outdated Show resolved Hide resolved
@m110 m110 marked this pull request as ready for review December 6, 2019 15:32
@@ -34,6 +34,11 @@ type HandlerFunc func(msg *Message) ([]*Message, error)
// NoPublishHandlerFunc is HandlerFunc alternative, which doesn't produce any messages.
type NoPublishHandlerFunc func(msg *Message) error

// PassthroughHandler is a handler that passes the message unchanged from the subscriber to the publisher.
var PassthroughHandler HandlerFunc = func(msg *Message) ([]*Message, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could use the alias Messages instead of []*Message, as we've done elsewhere.
If you think it'll improve readability

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HandlerFunc doesn't use it though, so maybe we should change them all at once?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm I thought I saw some HandlerFuncs using Messages instead, maybe I was wrong

}

// NewFanOut creates new FanOut.
// The passed router should not be running yet.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In principle, we could check if the router is already running (router.Running())?
Should we return error if this is the case?
Then cover it with the appropriate unit test ofc

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh right, that's a good idea. 👍

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See 6939c53

subscriber message.Subscriber,
logger watermill.LoggerAdapter,
) (*FanOut, error) {
if router == nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

basically, is there any case when we need to pass router?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to internal router in a96ad45

@m110 m110 merged commit 8840d3f into master Dec 20, 2019
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.

3 participants