Udhay
Udhay

Reputation: 81

How to log or handle original payload message in Mule

<flow>
<jms:inbound-endpoint queue="InputQueue"/>
<component class="MyComponent"/>
<choice>
    <when expression="/Response/Status/Success" evaluator="xpath">
         <jms:outbound-endpoint queue="LogInputQueue"/>
         <jms:outbound-endpoint queue="SuccessQueue"/>
    </when>
    <when expression="/Response/Status/Error" evaluator="xpath">
         <jms:outbound-endpoint queue="LogInputQueue"/>
         <jms:outbound-endpoint queue="ErrorQueue"/>
    </when>
    <otherwise>
        <jms:outbound-endpoint queue="LogInputQueue"/>
        <jms:outbound-endpoint queue="ExceptionQueue"/>
    </otherwise>
</choice>
</flow>

In this flow, MyComponent returns either success message as a response or error response or exception?

I need to log the original message from InputQueue in LogInputQueue in all the cases. How do I achieve this in my flow?

Upvotes: 2

Views: 4069

Answers (3)

Anirban Sen Chowdhary
Anirban Sen Chowdhary

Reputation: 8311

Since, you need to send original message from InputQueue to LogInputQueue in all the cases, as you mentioned, what you need to do is :-
1. Remove <jms:outbound-endpoint queue="LogInputQueue"/> from all the cases in choice block
2. Store the original payload from InputQueue in a variable by placing it just after the JMS inbound endpoint
3. At the end of the flow, after the choice router, set the payload in set payload component from variable you stored the original payload
4. Now put <jms:outbound-endpoint queue="LogInputQueue"/> after your set payload component.

In this way you will able to send the original payload to the LogInputQueue as per your requirement.

Upvotes: 0

krishna
krishna

Reputation: 1

Using log4j or slf4j you can log the payload.

[payload],we have logger component using this log payload in console.

Upvotes: 0

Chinmoy
Chinmoy

Reputation: 1754

Did you mean to create a log file? In that case, you have to implement log4j using slf4j and use the line

<logger level="log_level" category="your_category" message="#[message:payload]"/>

where log_level is your desired logging level- "error", "debug", "info" etc...

your_category is your category of log defined in the log4j.properties file (it is optional actually)

and message="#[expression:value]" is your message to be logged given as an expression:scope:key combination. Scope is optional here.

Upvotes: 2

Related Questions