-
Notifications
You must be signed in to change notification settings - Fork 12
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 SSERouter #3
Conversation
logger watermill.LoggerAdapter | ||
} | ||
|
||
func NewSSERouter( |
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.
Maybe we could add some documentation about what to pass as upstreamRouter
here. upstreamSubscriber
is maybe a little bit more intuitive, but what is the router here for?
What arguments to pass to the constructor?
I figure that there will be an example for SSE in due time, but I feel that a godoc might help
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.
Yeah, will add it. 👍
This is a proposal for a thin abstraction of SSE router and handlers.
The idea is that it's enough to prepare two method for implementing a SSE handler:
GetResponse
- returns a model of response to be marshalled and rendered. Typically, this will get some kind of identifier from request (r
) and fetch the payload from a repository / application query handler.Validate
- checks if the incoming message should be handled. For example, the handler could consumepost-updated
topic, which has updates to all posts in the system. This method should unmarshall the payload and check if the ID matches the one in request (r
) - or even better, check in message's metadata if available.See tests for an example implementation.
How the handler works:
event-stream
inAccept
header, return model fromResponseProvider
.GetResponse
and start the stream.Message
withValidate
and push new model to stream each time it passes.Out of scope / TODO: