如果某个会话变量为false或true,则需要过滤消息
flow.xml
<spring:beans>
<spring:bean id="serviceBean" class="com.uidai.ServiceBean"/>
</spring:beans>
<flow name="messagefilterFlow1" doc:name="messagefilterFlow1">
<file:inbound-endpoint responseTimeout="10000" doc:name="File" path="D:/sample" />
<invoke object-ref="serviceBean" method="enrichFilter" doc:name="Invoke" methodArguments="#[sessionVars],#[message]"/>
<logger level="INFO" message="#[sessionVars['filter']]" doc:name="Logger"/>
<!--<message-property-filter pattern="#[sessionVars['filter']]=true" caseSensitive="true" doc:name="Message Property"/>-->
<expression-filter expression="#[sessionVars['filter']]" doc:name="Expression"/>
<file:outbound-endpoint responseTimeout="10000" doc:name="File" path="D:/sample2"/>
</flow>
服务bean方法
public void enrichFilter(MessagePropertyMapContext mapContext, MessageContext messageContext){
mapContext.put("filter", false);
System.out.println("mapContext" + mapContext);
System.out.println("message Context:::" + messageContext);
}
Reading a file from inbound and setting a session variable in spring bean method. Wanted to filter the message on basis of filter value so that if filter value is true outbound file is not written and message is filtered. Even if filter value is true or false a lock is hold on file by inbound endpoint and processing stops.
答案 0 :(得分:0)
我无法在3.5.2上重现。
我建议你在方法accept()中的ExpressionFilter.class中加一个断点,以实现为什么行return muleContext.getExpressionManager().evaluateBoolean(expr, message, nullReturnsTrue, !nullReturnsTrue);
总是为你返回false
。
利用可能性较小的魔法的另一个建议是通过实现Filter interfance然后使用custom-filter元素来预先返回到过滤器表达式和/或实现java过滤器。