Comments (4)
My guess is you'd have to have a composite of struct each listening for a single event type.
Correct. In this situation, I will suggest to not put any logic to Handle()
but just call another service which will be the same for both.
from watermill.
@delaneyj Have you find a way that satisfied your request?
@roblaszczak Can you write example, please?
from watermill.
example:
type readModelBuilder interface {
buildBookingsReadModel(guestName string) error
}
type BookingsFinancialReport struct {
readModelBuilder readModelBuilder
}
func (b BookingsFinancialReport) HandlerName() string {
// this name is passed to EventsSubscriberConstructor and used to generate queue name
return "BookingsFinancialReport"
}
func (BookingsFinancialReport) NewEvent() interface{} {
return &RoomBooked{}
}
func (b *BookingsFinancialReport) Handle(ctx context.Context, e interface{}) error {
event := e.(*RoomBooked)
return b.readModelBuilder.buildBookingsReadModel(event.GuestName)
}
type SpecialBookingsFinancialReport struct {
readModelBuilder readModelBuilder
}
func (b SpecialBookingsFinancialReport) HandlerName() string {
return "SpecialBookingsFinancialReport"
}
func (SpecialBookingsFinancialReport) NewEvent() interface{} {
return &SpecialRoomBooked{}
}
func (b *SpecialBookingsFinancialReport) Handle(ctx context.Context, e interface{}) error {
event := e.(*SpecialRoomBooked)
return b.readModelBuilder.buildBookingsReadModel(event.VIPGuestName)
}
In that case, EventHandler is just calling something which is responsible for building read models (also, Single Responsibility Principle will be satisfied here :)).
did it help? :)
from watermill.
I hope this is clean. If not - please let us know :)
from watermill.
Related Issues (20)
- How to subscribe to all gochannel ? HOT 2
- Any plans to add support of RabbitMQ Streaming?
- Generated topic names for PubSub tests does not conform with Azure guidelines
- How to delete message after ack? HOT 1
- Context not being propagated through command bus HOT 2
- Is it possible to get google pubsub server generated unique message-id? HOT 3
- Data race on Publish for Google pubsub
- SQLite driver HOT 4
- Log custom fields inside message router
- Invalid publisher name in metrics
- Resume after shutdown always fetch last interrupted message again
- How to process a batch of received messages instead of a single piece?
- Can you output the message metadata to the logs?
- Only post messages after subscribing
- Watermill tests fail on windows
- The publish signature does not allow for a context.Context to be passed HOT 2
- Router closes publisher before message processing is done
- Removing usage of https://github.com/hashicorp/go-multierror
- [watermill-http] Custom HTTP response status HOT 2
- [watermill-kafka] is watermill-kafka still maintained? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from watermill.