0
votes

I'd like to send a JMS message at the beginning and end of processing a REST request. I can do something like this:

<set-variable variableName="savedPayload" value="#[payload]" doc:name="Variable" />
<scripting:component doc:name="Groovy">
    <scripting:script engine="Groovy">
        <scripting:text><![CDATA[
            '{"event" : "TRY"}'
        ]]></scripting:text>
    </scripting:script>
</scripting:component>
<jms:outbound-endpoint queue="event.detail" connector-ref="jmsConnector" />
<expression-transformer evaluator="groovy" expression="savedPayload" />

Essentially, the JMS would just be used to record the entry and exit (SUCCESS or FAILED) while preserving the saved message, which the code above does using a variable. What's a shorter, idiomatic way of doing this in a Mule flow?

Edit:

To put this another way, is there a way to send that outbound message with a payload without the save/restore needed to hang on to the response payload?

3

3 Answers

1
votes

You can use Async scope. It will execute asynchronously your message processors in a different branch and you won't have to worry about saving/restoring the payload.

<async>
    <scripting:component doc:name="Groovy">
      <scripting:script engine="Groovy">
        <scripting:text><![CDATA[
            '{"event" : "TRY"}'
        ]]></scripting:text>
      </scripting:script>
   </scripting:component>
  <jms:outbound-endpoint queue="event.detail" connector-ref="jmsConnector" />
</async>

more details about async scope: http://www.mulesoft.org/documentation/display/current/Async+Scope+Reference

0
votes

Try using the Wire Tap router. This way you can pass you paylaod to another channel where you can modify or outbound it without distrubing your main cahnnel. Mule Routers Guide

0
votes

The best option will be message enricher :- https://developer.mulesoft.com/docs/display/current/Message+Enricher
Message enricher component doesn't disturb the existing payload and you can set anything inside it... it will not affect the payload