4

I have an abstract-message-processor I built that I want to encapsulate inside of a boolean evaluation so that I can turn it off under certain conditions. I'm looking to write something like this:

<flow name="myFlow">
    <if expression="${myFlag} == true">
        <mynamespace:myCustomMessageProcessor .../>
    </if>
</flow>

Is this possible in Mule ESB? Is there an example I can review?

TERACytE
  • 7,553
  • 13
  • 75
  • 111
  • 4
    From what I see here http://stackoverflow.com/questions/13094092/how-to-kick-off-a-mule-flow-to-read-messages-from-a-jms-queue-using-an-http-endp you could use `` – Alex Mar 07 '13 at 17:00
  • Do you want to perform any action after the "if" in this flow? – David Dossot Mar 07 '13 at 17:25
  • No, I only want to invoke the message processor under certain conditions. I don't need any other actions. – TERACytE Mar 07 '13 at 17:35
  • Alex, it looks like this would work. And here I was searching for ht e work "if/then" in the Mule documentation, instead of "choice" :) Can you post your answer as an official answer to my question? – TERACytE Mar 13 '13 at 19:55

4 Answers4

2

This is a standard content-based routing pattern present in all ESB products.

In Mule, you want to use Choice Router - see e.g. Mule School: Using Flow Controls – Choice Router tutorial.

Aleš
  • 8,896
  • 8
  • 62
  • 107
1

If you want to use IF condition reading the value from a properties file you can do the following :-

<scripting:component doc:name="Groovy" doc:description="This component is used to check the value from properties file" >
  <scripting:script engine="Groovy">
     // use your if else code here like  
     if(${myFlag} == true)
         {      
         return message.payload
         }
   </scripting:script>
 </scripting:component>

Let me know it worked or not ....

Anirban Sen Chowdhary
  • 8,233
  • 6
  • 39
  • 81
0

Mule Choice Router is the apt option for using the if else or if elseif implementation. Even you make use of expressions to achieve the same.

ARUN KUMAR
  • 89
  • 1
  • 9
0

Mule allows the condition check by using the <choice> router. You can define different <when> and one <othterwise> condition for fallback decisions.

<choice doc:name="Choice condition">
  <when expression="#[flowVars.myVar = 'on']">
    <logger level="INFO" message="Case: myVar is on" />
  </when>
  <when expression="#[flowVars.myVar = 'off']">
    <logger level="INFO" message="Case: myVar is off" />
  </when>
  <otherwise>
    <logger level="INFO" message="Case: otherwise the default route is used" />
  </otherwise>
</choice>
Ben Asmussen
  • 964
  • 11
  • 15