Using Clone and Aggregate Mediators — WSO2 ESB

Joy Rathnayake
WSO2 Solution Architecture Team Blog
3 min readMar 26, 2019

WSO2 Enterprise Integrator (WSO2 EI) is a comprehensive integration solution that enables communication among various, disparate applications.

WSO2 Enterprise Integrator comes with many profiles which includes ESB profile, Business Process profile, Micro Integrator profile and Message Broker profile.

WSO2 EI ESB profile is mainly responsible for handling message transformations, and routing the messages to their appropriate destinations.

Recently, I came across a requirement for implementing a small POC for demonstrating below use case using WSO2 EI ESB profile:

Business Use Case
  • User/ caller sends a request to a service by submitting an input
  • Actual business requirement requires executing 03 different back-end services (Service 1/ Service 2/ Service 3) in order to complete the use case
  • WSO2 ESB receives the user/ caller request and routes the request/ input to 03 back-end services in parallel
  • Once all 03 back-end services are executed, WSO2 ESB aggregates the responses into a single response and routes back to the user/ caller

The above requirement is more or less aligned with the Recipient List and Aggregate message routing enterprise integration patterns.

WSO2 EI provides mediators to support almost every enterprise integration patterns and I used Clone mediator and Aggregate mediator to build the POC.

Below is the source for InSequence which creates a Clone mediator and call 03 service endpoints in parallel. It’s important to give a value to the id property which we will use to link with the Aggregate mediator later on.

Source — InSequence

Below is the source for OutSequence which creates a Property mediator and an Aggregate mediator.

Source — OutSequence

As you can see, we use a Property mediator before the Aggregate mediator and it’s important to give a value to the name property which we use to associate with the aggregate mediator by setting it to enclosingElementProperty property. Also it’s important to give the same id which we assigned to Clone mediator as the id of Aggregate mediator. Then Aggregate knows what to aggregate and which responses to aggregate.

Finally, we have the Send mediator to send the aggregated output to the user/ caller.

Below is the completed mediation message flow with some addition Log mediators in place for instrumentation purpose.

Message Mediation Flow

When the user/ caller execute the API which is exposed by the ESB, it clones the request and routes it to the 03 back-end services and the response will be aggregated and returned to the user/ caller.

Aggregated Response

--

--

Joy Rathnayake
WSO2 Solution Architecture Team Blog

Solutions Architect | Public Speaker | MVP | MCT | Trainer | Author | Mentor | Community Leader | Blogger