-
Notifications
You must be signed in to change notification settings - Fork 395
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
Add FanOut proposal #166
Conversation
@@ -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) { |
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.
You could use the alias Messages
instead of []*Message
, as we've done elsewhere.
If you think it'll improve readability
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.
HandlerFunc
doesn't use it though, so maybe we should change them all at once?
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.
hmm I thought I saw some HandlerFunc
s using Messages
instead, maybe I was wrong
pubsub/gochannel/fanout.go
Outdated
} | ||
|
||
// NewFanOut creates new FanOut. | ||
// The passed router should not be running yet. |
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.
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
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.
Oh right, that's a good idea. 👍
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.
See 6939c53
pubsub/gochannel/fanout.go
Outdated
subscriber message.Subscriber, | ||
logger watermill.LoggerAdapter, | ||
) (*FanOut, error) { | ||
if router == nil { |
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.
basically, is there any case when we need to pass router?
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.
Moved to internal router in a96ad45
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.