你能在Mule ESB中编写一个“if”语句吗?

4

我有一个抽象的消息处理器,我想将其封装在布尔值评估中,以便在某些条件下关闭它。我想写出类似这样的代码:

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

这在Mule ESB中是否可行?是否有示例可供参考?

4
根据我在这里看到的:http://stackoverflow.com/questions/13094092/how-to-kick-off-a-mule-flow-to-read-messages-from-a-jms-queue-using-an-http-endp,您可以使用`<choice><when...>`。 - Alex
在这个流程中,你想在“if”之后执行任何操作吗? - David Dossot
不,我只想在特定条件下调用消息处理器。我不需要任何其他操作。 - TERACytE
Alex,看起来这个会起作用。我一直在Mule文档中搜索“if/then”而不是“choice” :) 你能把你的答案发布为我的问题的官方答案吗? - TERACytE
4个回答

2

1
如果您想使用IF条件从属性文件中读取值,可以按照以下步骤进行:
<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>

请让我知道它是否起作用了....

0
Mule Choice Router是使用if else或if elseif实现的合适选项。您甚至可以使用表达式来实现相同的功能。

0
Mule允许使用<choice>路由器进行条件检查。您可以定义不同的<when>和一个<otherwise>条件,用于回退决策。
<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>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接