I'm currently developing an application using reactive programming. Every entity creation or modification in the system publishes an event and no two entities can be created/modified within the same use case.
In this situation, there are entities that have to be created based on specific states of other entities. For example, there is an entity Slot that, when created with a state IN_AUCTION, should trigger the creation of an Auction entity. This is optional, as the Slot could be created with a state AVAILABLE, in which case, no Auction should be created.
Given this is the case, my doubt is about the type of event to publish when the Slot is created. These are the options I've thought about:
- Publish a generic SlotCreatedEvent. In this case, the listener would need to verify the state of the Slot, either by adding it to the Slot event or by querying it to check its state.
- Publish a SlotInAuctionEvent or a SlotAvailableEvent. In this case, there would be a specific listener that would create the Auction without checking the Slot state but if I follow this approach I could have an explosion of events.
So, given this example, what's the expected granularity when publishing events? Should there be a specific event for each state/entity modification or just a generic one with all the information of the entity modified?
SlotInAuctionEvent
that only creates an auction if the required conditions exist?SlotInAuctionEvent
indicates that the condition has been met. The question is if it is a good idea to have a separate event for every state in which a slot can be created vs. having one event that provides the data for the listeners to do the condition-checking.SlotFactory
checks the condition and then triggers (via event or otherwise) the creation of an auction? I think that's basically option 2 in that you need a separate event for each condition. Or did I misunderstand?