You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Amruta Jawlekar <am...@ignitiv.com> on 2017/02/27 12:51:36 UTC

Stop polling the input folder after the scheduled route is completed

Hi,

I am working on a project which polls to one input folder, processes it and
keeps the processed files to output folder. The input files are then moved
to Backup folder.
Now I want to keep this on scheduler twice a day at fixed time. I did that
using CronScheduledRoutePolicy. Below is the code. 
The job runs on the scheduled hour, once all files are processed if I keep
another files to same input folders it processes those too. Cannot use
routeEndTime because I am not sure how much time it will take to process all
files.

How do I ask Camel to stop polling to input folder until the next scheduled
time. I want the route to run at 12pm noon and 6pm, and not continuously
poll the input folder. 

	<bean id="startPolicy"
class="org.apache.camel.routepolicy.quartz.CronScheduledRoutePolicy">
	    <property name="routeStartTime" value="0 00 12,18 * * ?"/>
	</bean>

	<camelContext trace="true"
		xmlns="http://camel.apache.org/schema/spring">
		<camel:route id="inputFiles" routePolicyRef="startPolicy"
autoStartup="false">
..........
</camelContext>

I tried using Quartz but was not successful. If it is possible using Quartz
and there is any link for Quartz example with spring camel context, then
please let me know.

Thanks,
Amruta



--
View this message in context: http://camel.465427.n5.nabble.com/Stop-polling-the-input-folder-after-the-scheduled-route-is-completed-tp5794516.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Stop polling the input folder after the scheduled route is completed

Posted by Claus Ibsen <cl...@gmail.com>.
You can use controlbus to stop the rout from the route, you can do
that when the batch is complete = true so you know you have processed
all the files from the poll.

And set async=true in the controlbus in the stop

On Mon, Feb 27, 2017 at 1:51 PM, Amruta Jawlekar <am...@ignitiv.com> wrote:
> Hi,
>
> I am working on a project which polls to one input folder, processes it and
> keeps the processed files to output folder. The input files are then moved
> to Backup folder.
> Now I want to keep this on scheduler twice a day at fixed time. I did that
> using CronScheduledRoutePolicy. Below is the code.
> The job runs on the scheduled hour, once all files are processed if I keep
> another files to same input folders it processes those too. Cannot use
> routeEndTime because I am not sure how much time it will take to process all
> files.
>
> How do I ask Camel to stop polling to input folder until the next scheduled
> time. I want the route to run at 12pm noon and 6pm, and not continuously
> poll the input folder.
>
>         <bean id="startPolicy"
> class="org.apache.camel.routepolicy.quartz.CronScheduledRoutePolicy">
>             <property name="routeStartTime" value="0 00 12,18 * * ?"/>
>         </bean>
>
>         <camelContext trace="true"
>                 xmlns="http://camel.apache.org/schema/spring">
>                 <camel:route id="inputFiles" routePolicyRef="startPolicy"
> autoStartup="false">
> ..........
> </camelContext>
>
> I tried using Quartz but was not successful. If it is possible using Quartz
> and there is any link for Quartz example with spring camel context, then
> please let me know.
>
> Thanks,
> Amruta
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Stop-polling-the-input-folder-after-the-scheduled-route-is-completed-tp5794516.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2: https://www.manning.com/ibsen2

Re: Stop polling the input folder after the scheduled route is completed

Posted by Amruta Jawlekar <am...@ignitiv.com>.
I was able to stop the route finally. 
What I did was - 
1. set sendEmptyMessageWhenIdle=true in the file component. So when all
files from input folder are read and moved to backup folder, it sends empty
message.
2. On empty body, I am calling a processor.
3. And in processor, I am again checking if the folder is empty and then
using 
exchange.getContext().stopRoute("inputFiles", 5, TimeUnit.SECONDS);
to stop the route.

Now the route is stopped until the next scheduled time. :)

Thanks for your inputs.



--
View this message in context: http://camel.465427.n5.nabble.com/Stop-polling-the-input-folder-after-the-scheduled-route-is-completed-tp5794516p5794540.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Stop polling the input folder after the scheduled route is completed

Posted by Amruta Jawlekar <am...@ignitiv.com>.
Hi souciance,

My route code : 
		
		<camel:route id="inputFiles" routePolicyRef="startPolicy"
autoStartup="false">
			
			<camel:from
uri="file://{{inputfolder}}?move=../{{backupfolder}}/${date:now:yyyyMMdd_HHmmss}/${file:name}"/>
			<camel:choice>
				<camel:when>
					
					<camel:simple>${body} != null &amp;&amp; ${file:ext} ==
'dcn'</camel:simple>					
					<camel:to uri="direct:processFileImport" />
				</camel:when>
				<camel:when>
					
					<camel:simple>${body} != null &amp;&amp; ${file:ext} !=
'dcn'</camel:simple>
					<camel:to uri="file://unprocessed" />
				</camel:when>
			</camel:choice>			
		</camel:route>



--
View this message in context: http://camel.465427.n5.nabble.com/Stop-polling-the-input-folder-after-the-scheduled-route-is-completed-tp5794516p5794538.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Stop polling the input folder after the scheduled route is completed

Posted by souciance <so...@gmail.com>.
Did you try to stop the route after polling was done? How does your route
code look like?

On Mon, Feb 27, 2017 at 1:51 PM, Amruta Jawlekar [via Camel] <
ml-node+s465427n5794516h59@n5.nabble.com> wrote:

> Hi,
>
> I am working on a project which polls to one input folder, processes it
> and keeps the processed files to output folder. The input files are then
> moved to Backup folder.
> Now I want to keep this on scheduler twice a day at fixed time. I did that
> using CronScheduledRoutePolicy. Below is the code.
> The job runs on the scheduled hour, once all files are processed if I keep
> another files to same input folders it processes those too. Cannot use
> routeEndTime because I am not sure how much time it will take to process
> all files.
>
> How do I ask Camel to stop polling to input folder until the next
> scheduled time. I want the route to run at 12pm noon and 6pm, and not
> continuously poll the input folder.
>
>         <bean id="startPolicy" class="org.apache.camel.routepolicy.quartz.
> CronScheduledRoutePolicy">
>             <property name="routeStartTime" value="0 00 12,18 * * ?"/>
>         </bean>
>
>         <camelContext trace="true"
>                 xmlns="http://camel.apache.org/schema/spring">
>                 <camel:route id="inputFiles" routePolicyRef="startPolicy"
> autoStartup="false">
> ..........
> </camelContext>
>
> I tried using Quartz but was not successful. If it is possible using
> Quartz and there is any link for Quartz example with spring camel context,
> then please let me know.
>
> Thanks,
> Amruta
>
> ------------------------------
> If you reply to this email, your message will be added to the discussion
> below:
> http://camel.465427.n5.nabble.com/Stop-polling-the-input-
> folder-after-the-scheduled-route-is-completed-tp5794516.html
> To start a new topic under Camel - Users, email
> ml-node+s465427n465428h31@n5.nabble.com
> To unsubscribe from Camel - Users, click here
> <http://camel.465427.n5.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=465428&code=c291Y2lhbmNlLmVxZGFtLnJhc2h0aUBnbWFpbC5jb218NDY1NDI4fDE1MzI5MTE2NTY=>
> .
> NAML
> <http://camel.465427.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>




--
View this message in context: http://camel.465427.n5.nabble.com/Stop-polling-the-input-folder-after-the-scheduled-route-is-completed-tp5794516p5794517.html
Sent from the Camel - Users mailing list archive at Nabble.com.