If you went to a university before, say, 2010, do you remember the ride boards?
People going from the university town to some other place would post little notices of where they were going and how much they would charge for a ride.
You would walk by there every so often and see if there were any messages that interested you and react when there were.
That was pub/sub. It’s pretty simple.
Message stores provide pub/sub communication
In our model, when you see funds-transfer-component
observing account-component
’s events, understand it consumes those messages via pub/sub. It doesn’t really know where the events come from. It just knows they appeared in the right stream category and that they have the right metadata.correlation_stream_name
, which it gets from how it starts its consumer:
Consumers::Account::Events.start('account', correlation: 'fundsTransfer')
Once in the handler, it handles it like it would any message by:
- Figuring out which entity it’s dealing with
- Projecting the current state of the entity
- Seeing if it has already processed the message
- Doing and recording the work of processing the message
And that’s a wrap!
Thank you for the question all those days ago, Daniel. Yes, a single command can lead to more than one event and even more than one additional command.
Your workflows are what they are, and you design what it takes to handle them. If your design leads you to producing more than one message, that’s not even a design smell. It’s just part of the process.