如何使用HTTP端点启动mule流以从JMS队列读取消息

时间:2012-10-26 20:37:34

标签: jms esb mule flow

我基本上有两个流程:

  1. HTTP入站端点接收批处理XML,拆分为单个部分并将其分级到JMS队列。
  2. 从JMS队列中读取暂存的XML并处理消息。
  3. 我需要使用Rest调用来控制上面的流2的执行(即)流2应该仅在接收到HTTP入站呼叫时运行。我使用的是Mule版本3.2.2

    以下是流程:

             <flow name="flow-stage-input">
               <http:inbound-endpoint   host="localhost" 
                            port=   "8082" 
                            path=   "test/order"
                            exchange-pattern=   "request-response"
                                        >
    
               </http:inbound-endpoint>
              <object-to-string-transformer></object-to-string-transformer>
              <splitter evaluator="xpath" expression="//Test/TestNode" enableCorrelation="ALWAYS"/>
              <custom-transformer class="org.testing.transformers.DocumentToString"></custom-transformer>
    
              <pooled-component>
                    <spring-object bean="receiver"></spring-object>
              </pooled-component>
    
              <!-- DECIDE SUCCESS OR FAILURE --> 
              <choice>
                    <when expression="//Test/TestNode" evaluator="xpath">
                <jms:outbound-endpoint queue="stagingQueue" exchange-pattern="one-way" connector-ref="jmsConnector" />
                </when>
                <otherwise>
                    <logger message="Skipped staging message due to errors" level="ERROR" /> 
                </otherwise>
              </choice>
              <collection-aggregator></collection-aggregator>
              <custom-transformer class="org.testing.transformers.ListOfStringsToString"></custom-transformer>
              <!-- RESPONSE SENT BACK TO CALLER -->
            </flow>
    
    
    
    
            <flow name="flow-process-jms-input" > 
               <jms:inbound-endpoint  queue="stagingQueue" exchange-pattern="one-way" connector-ref="jmsConnector" />
               <pooled-component>
                <spring-object bean="processor"></spring-object>
               </pooled-component>
               <!-- DECIDE SUCCESS OR FAILURE  -->
               <choice>
                     <when expression="//ErrorCondition/Path" evaluator="xpath">
                    <jms:outbound-endpoint queue="errorQueue" exchange-pattern="one-way" connector-ref="jmsConnector" />
                 </when>
                 <otherwise>
                    <logger message="Message processed successfully" level="ERROR" /> 
                 </otherwise>
               </choice>
             </flow>
    

1 个答案:

答案 0 :(得分:2)

使用流2中的Groovy脚本使用以下命令从队列中请求一条JMS消息:

muleContext.client.request("jms://stagingQueue", 0)

如果队列为空,则返回null,否则返回包含JMS消息的Mule消息。