Search code examples
mulemulesoftmule4

mule 4 : http request from one api to another - correlation id being sent implicitly but not other headers


Am using Mule runtime 4.4 Have two api - api 1 receives request over http and then calls api2 again over http api 1 receives a GET request with two headers:

X-Correlation-Id = abcd
X-Channel = Music

api 1 then makes a call to api 2 BUT it does NOT send any of the headers

However when request is received in api2 we can see the header X-Correlation-Id = abcd ( unexpected behaviour ? )

However the other header X-Channel = Music is missing ( expected behaviour )

Here is the complete code : api1 :

    <?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns="http://www.mulesoft.org/schema/mule/core"
    xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd">
    <http:listener-config name="HTTP_Listener_config" doc:name="HTTP Listener config" doc:id="f1bec56d-de65-4a93-913d-07a7426d6bf6" >
        <http:listener-connection host="0.0.0.0" port="9091" />
    </http:listener-config>
    <http:request-config name="HTTP_Request_configuration" doc:name="HTTP Request configuration" doc:id="7040eda0-aff5-47c2-8682-be73489e2c2c" >
        <http:request-connection host="localhost" port="9092" />
    </http:request-config>
    <flow name="header_pass_01Flow" doc:id="dc0c28a7-c277-4192-b641-e73af8afbde3" >
        <http:listener doc:name="Listener" doc:id="57e56cd6-a47e-456b-8c6d-e57627c673b8" path="/pass/*" config-ref="HTTP_Listener_config"/>
        <logger level="INFO" doc:name="Logger" doc:id="6df37e5e-a491-421c-a642-742059107d95" message="before call to api 1"/>
        <http:request method="GET" doc:name="Request" doc:id="a6765e5d-40f5-4abd-bff6-d6e6a80eecdf" config-ref="HTTP_Request_configuration" path="/receive/all"/>
        <logger level="INFO" doc:name="Logger" doc:id="e250696f-7109-42a4-a50c-586fc164fed9" message="after call to api 1"/>
    </flow>
</mule>

api2 :

    <?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns="http://www.mulesoft.org/schema/mule/core"
    xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd">
    <http:listener-config name="HTTP_Listener_config" doc:name="HTTP Listener config" doc:id="a1f75f77-5ff5-4346-866e-0f1ce1679e57">
        <http:listener-connection host="0.0.0.0" port="9092" />
    </http:listener-config>
    <flow name="header_receive_01Flow" doc:id="433cc316-549d-4349-86ba-68e3571a5716" >
        <http:listener doc:name="Listener" doc:id="d3677aa5-bd38-41d4-ba33-cb4a8a1fd2b2" config-ref="HTTP_Listener_config" path="/receive/*"/>
        <logger level="INFO" doc:name="Logger" doc:id="6999dea6-c369-4813-a5e6-8e81ec98ef60" message="received call"/>
    </flow>
</mule>

How is it that X-Correlation-Id is implicitly being passed ?


Solution

  • The correlation id is the identifier for Mule events, meaning is part of the core functionality of Mule 4. Other attributes or headers are added either by connectors or custom code/operations. Some connectors like the HTTP connector send it by default.