Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Multicasting (Scatter-Gather) Messages With MuleSoft

DZone's Guide to

Multicasting (Scatter-Gather) Messages With MuleSoft

Scatter Gather is used to send messages to multiple destinations concurrently and aggregate the responses into a message.

· Integration Zone
Free Resource

Migrating from On-Prem to Cloud Middleware? Here’s what Aberdeen Group says leading companies should be considering. Brought to you in partnershp with Liaison Technologies

Multicasting of messages with Mulesoft can be achieved using Scatter-Gather, which concurrently casts messages to each route. It collects results from all the routes and aggregates them into a single message.

During Scatter-Gather processing, if any of the routes fail, it doesn't stop sending messages to other configured routes — so it is possible that one or more configured routes can fail concurrently.

By default, if any of the routers fail during Scatter-Gather processing, the following action will be performed:

  • Set an exception payload for each failed route.

  • Throw a CompositeRoutingException.

CompositeRoutingException extends MessagingException to aggregate exceptions from different routes in the context of a single message router. Exceptions are correlated to each route through a sequential ID.

Scatter-Gather applications will not start if you have configured with less than two routes. It should always contain two or more routes.

Let's walk through setting up Scatter-Gather with Mule application.

Setting Up HTTP Listener With Mule Flow

First, you need to place the HTTP listener to the source of Mule flow and configure it. You can invoke the Mule flow by sending a request over HTTP.

Image title

Configuring Scatter-Gather Route With Mule Flow

Now, you need to drop the Scatter-Gather route in the Message Processor of the Mule Flow. You need to send a message concurrently to multiple routes via HTTP, JMS, Web Service Consumer, File, etc.  To achieve this, we will add different connectors under the Scatter-Gather route, place them in parallel, and configure all the connectors in the Scatter-Gather route.Image title

In the above screenshot, you can see that TransformMessage has been used after Web Service Consumer and HTTP Requestor. Basically, we are getting results back from both endpoints and we are transforming both responses to a single generic format as a response from both routes will be in a different format.

One more transformation has been placed at the end of the Scatter-Gather route. This transformation aggregates the result from all the routes to the single message.

Image title

Testing the Application

You can use Postman to test the application. We will use the HTTP GET method to send a request to invoke the Mule flow.

Image title

Conclusion

Scatter-Gather is used to send messages to multiple destinations concurrently and aggregate the response from all into a single message. It is a very simple technique provided by Mulesoft to multicast messages.

I hope that this article clarifies all of the doubt that you may have with the Scatter-Gather route.

Here is the video tutorial:


Is iPaaS solving the right problems? Not knowing the fundamental difference between iPaaS and iPaaS+ could cost you down the road. Brought to you in partnership with Liaison Technologies.

Topics:
mulesoft ,scatter gather ,http listener ,multicasting ,integration ,tutorial

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}