Apisero is now part of NTT DATA - Learn more.

Search
Close this search box.

How payload, variable, and attributes behave when passing through different flows in Anypoint Studio(Mule 4)

Author: Sanket Kangle

When we pass through parent flow to child flow and come back to calling flow(parent flow), Understanding how a payload, variables, and attributes(headers, query parameters, etc) behave is important to design and build scalable architectures using MuleSoft.

Case 1: When using Flow Reference

When passing from parent flow to child flow using flow reference, Child flow can be a flow, a sub-flow, or a private flow. For all these flows as a child flows, payload, variables, and attributes behave in the same way.

Let’s assume in parent flow we have some Attributes, Payload, and Variables set. when we pass to the child flow using Flow reference, All can be accessed in the child flow, payload and variable can be modified in child flow and when returned to the parent flow, the changes are reflected in parent flow as well. The same is shown in the following exhibit.

Let us see the same with working example.

Below is parent flow and a child flow which is called using a flow reference.

When a request is made to HTTP listener, before going in the child flow the following is set:

Query parameters = Mule

Payload = initial payload

Variable = initial_var_value

We can see the same in the debugger as well, a breakpoint is added at childFlow Flow Reference to view the same

When we move to child flow, we can see we can access all this

We can also modify payload and variable in child flow, we will be setting it to:

Payload = “intermediate_payload”

Variable = “intermediate_var_value”

When we step back in parent flow, the changes are reflected in parent flow as well

Attributes remained unchanged.

We can access all this and modify in parent flow as well, finally we get final payload, and final variable as well.

Case 2: When using HTTP Request

When passing from parent flow to child flow using HTTP Request, Attributes are updated(attributes at starting in parents flow are not equal to attributes, Payload goes as it is and can be modified in child flow as well. Variable cannot be passed as a variable(you can pass it using attributes for the request, but not as a Variable) because HTTP request has only attributes and payload in its body. As the variable is not passed, it cannot be accessed or modified from child flow. When coming back to calling flow(parent flow), modified payload and variable (which was not passed to child flow) can be accessed and modified in the parent flow. The same is shown in the exhibit below.

Let us see the same with a working example.

Below is parent flow and a child flow which is called using a HTTP Request

When a request is made to HTTP listener, before going in the child flow the following is set:

Query parameters = Mule

Payload = initial payload

Variable = initial_var_value

We can see the same in debugger as well, a breakpoint is added at Request component to view the same

As we move to child flow, the attributes are replaced with new request’s attributes, payload remains the same and variable is not passed to child flow so it cannot be accessed nor modified from child flow.

Query parameter changed from “Mule” to “Anypoint”, and variable from parent flow is not accessible in child flow. However we can set a new variable in child flow whose scope will be limited to child flow only. When we go back to parent flow, the changes made in payload are reflected, attributes are lost again and the variable that was defined in child flow is also lost. But at the same time, the variable that was defined in parent flow is now accessible and can be modified.

After modifying this we get final payload and variable as follows at the end of the flow

One thing to note here is that, if the method in HTTP Request is GET, then the payload will be lost while moving from parent flow to child flow as GET HTTP request does not have a body.

This is how payload, variables, and attributes are passed, modified across the flows.

We use cookies on this site to enhance your user experience. For a complete overview of how we use cookies, please see our privacy policy.