Resource
- https://martinfowler.com/eaaDev/EventCollaboration.html
Digest
Interaction Model
Not limitted to WS type of thing, but things as simple as in-process objects interaction also follows these patterns.
Request/Response Model
- QUERY : One component needs information (STATE) that another has, so the needier component requests it
- COMMAND : One component needs another to do something, out goes another request.
Event Model
Instead of components making requests when they need something, components (SOURCE) raise events when things change. Other components (LISTENER) then listen to events and react appropriately.
Difference
- One obvious difference is that the events are sent to everyone else, not just those components that are going to react.
- The sender is just broadcasting the event, the sender does not need to know who is interested and who will respond.
- The sender does not have to care about responses, allowing us to add behavior by plugging new components onto the event bus.
Command
At times the distinction is little more than phrasing, but at other times it does open the mind to different ways of doing things.
- Command : tell the recipient to do something,
- Event : an event happened - inviting those interested to respond.
- Simple Call v.s. Collaboration between different Listeners
Query
- Query : Needier (Listener) query information from source. Request driven application speaks when spoke to.
- Information/state managed in one place
- Event : Source push information to Needier (Listener). Event driven application speaks when it has something to say.
- Information/state managed in different places (source + listeners)
- Information/state on listeners should be read-only
Pros/Cons
Pros
- The great strength of Event Collaboration is that it affords a very loose coupling between its components.
- A system that uses Event Collaboration is more resilient to breakdowns.
Cons
- A component may continue operating, but it will be working on out of date information if it's not receiving events as things change.
- Each individual component is simpler, the complexity of the interactions will increase.
- This is made worse because these interactions are not clear by reading the source code. With Event Collaboration you don't know who is listening to the events until run-time - which in practice means you can only find the links between the components in configuration data - and there may be multiple areas of configuration data.
Message Endpoint
Message Endpoint code is custom to both the application and the messaging system’s client API. It is the messaging endpoint code that takes that command or data, makes it into a message, and sends it on a particular messaging channel. It is the endpoint that receives a message, extracts the contents, and gives them to the application in a meaningful way.
The rest of the application knows little about message formats, messaging channels, or any of the other details of communicating with other applications via messaging. It just knows that it has a request or piece of data to send to another application, or is expecting those from another application.