TERACytE
TERACytE

Reputation: 7863

Can you write an "if" statement in Mule ESB?

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?

Upvotes: 4

Views: 6341

Answers (4)

Ben Asmussen
Ben Asmussen

Reputation: 994

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>

Upvotes: 0

Anirban Sen Chowdhary
Anirban Sen Chowdhary

Reputation: 8321

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 ....

Upvotes: 1

ARUN KUMAR
ARUN KUMAR

Reputation: 89

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.

Upvotes: 0

Aleš
Aleš

Reputation: 9028

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.

Upvotes: 2

Related Questions