1. Home
  2. ...
  3. Mediation Interceptors
  4. Service Mashup

Service Mashup

Aggregator of asynchronous Service Callouts, allowing external calls to run in parallel.

Service Mashup is an aggregator of Service Callouts configured as asynchronous. By allowing external callouts to execute in parallel, Service Mashup provides an advantage over execution time of the call to the centralizing API by making better use of time, as demonstrated below.

NOTE

The Service Mashup stops the flow until the Service Callouts calls linked to it are completed.

Configuring the interceptor

The image below shows the settings for the interceptor:

  • Service callouts to wait: it lists all available asynchronous Service Callout instances that are not Fire and Forget and that are not contained in another Service Mashup.
  • Timeout (ms): it determines the timeout in milliseconds. If no value is inserted, the longest timeout configured among the selected Service Callouts will be applied.
  • Abort if any request fails: if selected, the request will be aborted if any of the Service Callouts fails. A failure occurs when the status code of the response is different from the expected.

How it works

To show how Service Mashup works, let's consider the following case:

NOTE

An organization, the LSA (Lost Souls' Alliance), will develop a central API, LSA Communication, which will be able to send, via POST, the same message (or command) to people inside and outside the organization. This API will be registered under the domain lsa.org.mx.

The message, sent as a JSON in the body of the call, will be:

The case of internal communication has been addressed in how Internal API Call works. The case of the external one, in how Service Callout works. Now let's combine these two communications into a single call.

The following images show, respectively, the sequence of the interceptors in the API flow and the settings used in the Service Mashup interceptor, which waits for the responses of the two Service Callout interceptors to continue the flow:

The settings used for the Internal API Call interceptor are the same as described in how it works. Those used for the two Service Callout interceptors are also the same as those described in how they work, except that the Asynchronous field has been checked and therefore the use of Service Mashup becomes necessary.

Unlike the case where the two Service Callout interceptors were configured to act synchronously, now both are executed in parallel. To take advantage of the waiting time, the Internal API Call is called after them, being executed while the other two calls are in progress.

At the end of the execution of the Internal API Call, the returned response, which is an object of type ApiResponse, is stored in the context variables. Next, the Service Mashup waits for the responses returned by the two Service Callout interceptors, which are objects of type RESTResponse, and also stores these responses in the context variables. To retrieve all responses, you must create a custom interceptor that accesses $call.contextVariables.get("Variable Name").

Below is the code for the custom JavaScript interceptor that will be used to capture all the responses and include the bodies and status in the final response:

Finally, the body of the response of the POST call to the all-messages resource of LSA Communication will be:

How happy are you with this page?

We use cookies to enhance your experience on our site. By continuing to browse, you agree to our use of cookies.Learn more