Mediator, as the name implies, mediates the message flow.
SOA is all about message flows between disparate systems, and mediators play an important role in this.
It forms the communication layer between the services, thus providing a kind of service virtualization and decoupling between the interacting services.
It basically intercepts the message flow between the services and offer various capabilities as listed below
- Message Routing : This is the ability to channel a request to a particular service provider based on the message. You may define rules to select the target service among the available services based on the content in the message(static routing) or based on an external rules engine(dynamic routing)
- Message Validation: Messages can be checked against a schematron file to check its validity. This helps in invoking the target services only with the right message(as each and every invocation in an enterprise is costly)
- Message Filtering : You may filter the messages based on its content
- Message Transformation : This is the ability to convert the structure and format of the incoming service request to the structure and format expected by the service provider.
Transformation is one of the key capabilities of the Mediators.
Mediators are also a way to change the interaction patterns, i.e. you can convert a message call from sync to async, a 2-way to a one-way, etc.
Mediators are a way to enable Event Delivery Architecture in your composite. They have the capability to publish an event as well as subscribe for an event.
However, mediators form the communication layer only within a composite. If the interactions go across composites, Enterprise Service Bus comes to the rescue. We’ll discuss about ESB later.