骡子动态条件
Mule dynamic conditions
我定义了一个外部 xml,其中包含很少的表达式。
<mule xmlns="http://www.mulesoft.org/schema/mule/core"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:spring-security="http://www.mulesoft.org/schema/mule/spring-security"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/3.1/mule.xsd
http://www.mulesoft.org/schema/mule/spring-security http://www.mulesoft.org/schema/mule/spring-security/3.1/mule-spring-security.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<beans:bean id="conditions" class="java.util.ArrayList" name="conditions">
<beans:constructor-arg>
<beans:list>
<beans:value>#[flowVars.price == '1000']</beans:value>
<beans:value>...</beans:value>
</beans:list>
</beans:constructor-arg>
</beans:bean>
</mule>
在主要流程中,我想评估这个表达式,但结果总是正确的。这是我到目前为止所做的。
<spring:beans>
<spring:import resource="classpath:my-conf-dir/expressions.xml"/>
</spring:beans>
<flow name="mainFlow" doc:name="mainFlow">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" doc:name="HTTP"/>
<expression-filter expression="#[payload != '/favicon.ico']" doc:name="Expression"/>
<set-variable variableName="price" value="1001" doc:name="Set Price" />
<foreach collection="#[app.registry.get('conditions')]" doc:name="For Each">
<logger message="Condition: #[payload]" level="INFO" doc:name="Logger"/>
<choice>
<when expression="#[payload]">
<logger message="OK" level="INFO" doc:name="Logger"/>
</when>
<otherwise>
<logger message="KO" level="INFO" doc:name="Logger"/>
</otherwise>
</choice>
</foreach>
</flow>
有什么方法可以计算表达式列表吗?
如有任何帮助,我们将不胜感激。
您好,您正在尝试做的事情无法完成,至少目前无法完成。
当您向 MEL 发送一个值时,就像您尝试这样做一样,将其评估为文字。
所以 true 不是 true 只是文字:
[flowVars.price == '1000']
您可以做的是获取#[flowVars[[=20=]].equals(payload)],其中 payload 是列表的值。
请注意我在比较字符串时使用了等号。
如果您提供更多背景信息,我们可能会更好地了解如何实现您想要的结果
也许您可以使用 java 组件并访问 eventContext.getMuleContext().getExpressionLanguage().evaluate
方法来评估表达式。
HTH,马科斯
我定义了一个外部 xml,其中包含很少的表达式。
<mule xmlns="http://www.mulesoft.org/schema/mule/core"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:spring-security="http://www.mulesoft.org/schema/mule/spring-security"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/3.1/mule.xsd
http://www.mulesoft.org/schema/mule/spring-security http://www.mulesoft.org/schema/mule/spring-security/3.1/mule-spring-security.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<beans:bean id="conditions" class="java.util.ArrayList" name="conditions">
<beans:constructor-arg>
<beans:list>
<beans:value>#[flowVars.price == '1000']</beans:value>
<beans:value>...</beans:value>
</beans:list>
</beans:constructor-arg>
</beans:bean>
</mule>
在主要流程中,我想评估这个表达式,但结果总是正确的。这是我到目前为止所做的。
<spring:beans>
<spring:import resource="classpath:my-conf-dir/expressions.xml"/>
</spring:beans>
<flow name="mainFlow" doc:name="mainFlow">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" doc:name="HTTP"/>
<expression-filter expression="#[payload != '/favicon.ico']" doc:name="Expression"/>
<set-variable variableName="price" value="1001" doc:name="Set Price" />
<foreach collection="#[app.registry.get('conditions')]" doc:name="For Each">
<logger message="Condition: #[payload]" level="INFO" doc:name="Logger"/>
<choice>
<when expression="#[payload]">
<logger message="OK" level="INFO" doc:name="Logger"/>
</when>
<otherwise>
<logger message="KO" level="INFO" doc:name="Logger"/>
</otherwise>
</choice>
</foreach>
</flow>
有什么方法可以计算表达式列表吗?
如有任何帮助,我们将不胜感激。
您好,您正在尝试做的事情无法完成,至少目前无法完成。
当您向 MEL 发送一个值时,就像您尝试这样做一样,将其评估为文字。 所以 true 不是 true 只是文字:
[flowVars.price == '1000']
您可以做的是获取#[flowVars[[=20=]].equals(payload)],其中 payload 是列表的值。 请注意我在比较字符串时使用了等号。
如果您提供更多背景信息,我们可能会更好地了解如何实现您想要的结果
也许您可以使用 java 组件并访问 eventContext.getMuleContext().getExpressionLanguage().evaluate
方法来评估表达式。
HTH,马科斯