Search code examples
regexmulemule-studiomule-componentmule-el

How to use flowVars inside wildcard filter and expression filter Mule


Is it possible to use the flowVariable inside wildcard or expression filter directly. I need to stop the flow based on the flow Variable value.

Example: My flow Variable name keyValue have the value like customer/feed/h26/h56 in this 'h26/h56' should set dynamically but customer/feed is constant always. I need to set my filter only after '/feed/' if it contain any characters.

  <flow name="testFlow1" doc:name="testFlow1">
    <file:inbound-endpoint responseTimeout="10000" doc:name="File" path="c:/in"/>
     .......( Many component)
    <set-variable variableName="keyValue" value="#[customer/feed/h26/h56]" doc:name="Variable"/>
     .......( Many component)    
     <message-filter doc:name="Message">
        <wildcard-filter pattern="customer/feed/+*" caseSensitive="true"/>
    </message-filter>
</flow>

Used + in pattern to check whether it contain one or more characters.

Also I used expression filter, not sure how to use flow Variable inside the filter expression. Could you please help me on this.

I don't want to use property filter.


Solution

  • Use expression filter instead, and since your expression is simple just use the startsWith method of String.

    for example

        <expression-filter expression="flowVars.keyValue.startsWith('customer/feed/')" doc:name="Expression"/>
    

    this will allow messages