2

I basically have two flows :

  1. HTTP Inbound endpoint receives batch XML, splits to individual pieces and stages it to a JMS queue.
  2. Reads the staged XMLs from the JMS queue and processes the messages.

I need to control the execution of flow 2 above using a Rest call (i.e) flow 2 should run only when an HTTP inbound call is received. I am using Mule version 3.2.2

Here are the flows:

 <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>
General Grievance
  • 4,555
  • 31
  • 31
  • 45

1 Answers1

2

Use a Groovy script in flow 2 to request one JMS message from the queue using:

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

This will return null if the queue was empty otherwise a Mule message containing the JMS message.

David Dossot
  • 33,403
  • 4
  • 38
  • 72
  • I am not sure how this satisfies my requirement. Sorry if I phrased it wrong above but I need to control whether flow 2 can run or not using an HTTP call (using an HTTP inbound endpoint). Basically, make an HTTP call to allow the flow to to start reading from the queue. – Sathya Pillutla Oct 29 '12 at 15:16
  • 1
    I didn't get you wanted to start/stop JMS consumption over HTTP, I thought you wanted to consume on demand. Then look at this answer stackoverflow.com/a/13078649/387927 : if you don't have any other JMS endpoints, you could have a 3rd flow to start/stop the JMS connector over HTTP. – David Dossot Oct 30 '12 at 22:04
  • Thanks, did not occur to me to split the connectors for reading and writing and disable one or the other. – Sathya Pillutla Nov 06 '12 at 21:03