Mule中的jms选择器表达式无法正常工作

时间:2015-04-27 11:04:47

标签: jms mule mule-studio

<flow name="readqueueFlow1" doc:name="readqueueFlow1" >
    <jms:inbound-endpoint queue="MyTestQueue" connector-ref="Active_MQ-Priority" doc:name="JMS">
        <jms:selector expression="JMSCorrelationID=’353’" />
    </jms:inbound-endpoint>
</flow>

它正在工作,但当我尝试使用下面的部署时,它没有部署

<!-- When we don't provide single quote it is failing in deployment -->
<jms:selector expression="JMSCorrelationID='#[flowVars.reqId]'" />

<!-- Payload contains reqId, when we provide it in single quote, it is assuming as a constant -->
<jms:selector expression="JMSCorrelationID='#[payload]'" />

2 个答案:

答案 0 :(得分:1)

我认为这是你给出的答案: - Using an expression in a JMS Selector in Mule 3

还有一件事,您无法使用#[flowVars.reqId]动态获取jms:selector值,因为流量变量范围仅限于流量...而是使用会话变量比如#[sessionVars.reqId] ..

您的流程将按以下方式进行修改: -

 <flow name="readqueueFlow1"  >
    <jms:inbound-endpoint queue="StudioOUT" connector-ref="Active_MQ" doc:name="JMS"/>
       <scripting:component>
    <scripting:script engine="groovy"><![CDATA[
        def jmsMessages = []

        for (def muleMessage = muleContext.client.request("jms://MyTestQueue?selector=JMSCorrelationID%3D'"+ sessionVars['reqId'] +"'", -1L);
         muleMessage != null;) {
      [] << muleMessage.payload
        }

        jmsMessages
    ]]></scripting:script>
</scripting:component>
  <logger level="INFO" message="#[message.payload]" doc:name="Logger"/>
</flow> 

您可以在此处看到使用Groovy Script将消息发送到队列,并且我使用会话变量而不是流变量

答案 1 :(得分:0)

jms:selector expression =&#34; putOnQueueTime&gt; ABC&#34;

可以在jms入站中使用上述表达式。