GithubHelp home page GithubHelp logo

Comments (4)

roblaszczak avatar roblaszczak commented on July 24, 2024

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.

Dionid avatar Dionid commented on July 24, 2024

@delaneyj Have you find a way that satisfied your request?
@roblaszczak Can you write example, please?

from watermill.

roblaszczak avatar roblaszczak commented on July 24, 2024

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.

roblaszczak avatar roblaszczak commented on July 24, 2024

I hope this is clean. If not - please let us know :)

from watermill.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.