MULESOFT-DEVELOPER-I practice question 15 of 30

A flow needs to combine and return data from two different data sources. It contains a Database SELECT operation followed by an HTTP Request operation. What is the method to capture both payloads so the payload from the second request does not overwrite that from the first?

Full set: 235 questions
Answer options
A: Put the Database SELECT operation inside a Cache scope
B: Put the Database SELECT operation inside a Message Enricher scope
C: Nothing, previous payloads are combined into the next payload
D: Save the payload from the Database SELECT operation to a variable Correct answer
Correct Answer:
D. Save the payload from the Database SELECT operation to a variable
Explanation

In a Mule flow, each component that generates an output (like a Database SELECT or HTTP Request) typically places its result into the payload of the Mule event. When components are sequenced, the payload from a subsequent component overwrites the existing payload. To preserve the data from the first operation (Database SELECT), its payload must be stored in a variable before the second operation (HTTP Request) is executed. This allows the flow to access both the original database results from the variable and the new HTTP response from the payload.

Why Incorrect

A. A Cache scope is used for performance optimization by storing and reusing responses from previous identical requests, not for combining payloads within a single flow execution.
B. A Message Enricher scope is a valid way to do this, but it works by storing the result in a target variable, making "Save to a variable" the more fundamental and correct principle.
C. This is incorrect. By default, the payload from the second operation overwrites the payload from the first; they are not automatically combined.

References

1. MuleSoft Documentation, "Mule Message Structure". This document explains that the payload is the main body of the message and can be modified by components in the flow. (Accessed via MuleSoft's official documentation site).

2. MuleSoft Documentation, "Variables in Mule". This section details how variables are used to store data at different scopes within a Mule application, which is the mechanism for preserving data that would otherwise be overwritten in the payload. (Accessed via MuleSoft's official documentation site).

3. MuleSoft Documentation, "Set Variable Component". "Use the Set Variable component to create or update a variable. You can use variables to store information to use later in the flow." (Reference: docs.mulesoft.com/mule-runtime/4.4/set-variable-component).

Scroll to Top