Reputation: 534
I have a rest webservice. Any request to this webservice is first stored in a folder (called inbox) using camel route. Another camel route listens to this folder and if server memory consumption is below threshold then puts request on JMS queue other wise it should put the request back in inbox folder.
So if memory consumption is above threshold, second route should keep on picking file from inbox folder and putting it back there in a recursive fashion. However this is not happening. Please provide some pointers on how to make this work. Below is the route that I am using:
<route>
<!-- Reading from MDW REST url -->
<from uri="mdw:REST/REST" />
<!-- Parsing OrderNumber and OrderVersion-->
<setHeader headerName="OrderNumber">
<xpath>Some path</xpath>
</setHeader>
<setHeader headerName="OrderVersion">
<xpath>Some path</xpath>
</setHeader>
<!-- Request being put in file folder -->
<to
uri="file:data/inbox?fileName=${header.OrderNumber}-${header.OrderVersion}.xml"
pattern="InOut" />
</route>
<!-- route with when clause: Checks memory consumption before putting message
on queue. If consumption below threshold put on queue
else put back into input folderk-->
<route>
<from uri="file:data/inbox" />
<camel:process ref="checkMemoryConsumption" />
<camel:when>
<!-- If -->
<camel:simple>${in.header.result} == 'true'</camel:simple>
<camel:convertBodyTo type="String" />
<to uri="jms queue"
pattern="InOut" />
</camel:when>
<camel:when>
<camel:simple>${in.header.result} == 'false'</camel:simple>
<camel:convertBodyTo type="String" />
<to uri="file:data/inbox" pattern="InOut" />
</camel:when>
</route>
Tried using a filter also but that doesnt work either. If the memory consumption is above threshold then camel puts the request in '.camel' folder. Instead the request should stay in input folder so that it be picked again and again until its actually put on the queue for processing.
<camel:route>
<camel:from uri="file:data/inbox"/>
<camel:filter>
<method ref="checkMemory" method="isFreeMemoryAboveSafeLimit"/>
<to uri="jms:queue:com.centurylink.mdw.external.event.queue"
pattern="InOut" />
</camel:filter>
Upvotes: 1
Views: 1707
Reputation: 534
Throwing an exception in your processor does the trick. What this does is it marks the message as failed and doesnt move it to .camel folder. So file consumer picks it up and processes it again.
Upvotes: 0
Reputation: 55750
Maybe use a file filter where you check the memory consumption and return true | false whether you want to accept the file. Then you dont need to add that choice in the route.
See the filter
option at
Upvotes: 1