You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by fxthomas <fe...@gmail.com> on 2016/02/01 15:17:08 UTC

Re: Camel file component URI dynamic options & Filter query

hello, 

        I have tried with  the  below route & filter configuration , its
works fine once , the filter is never called again  after the first run  .
Do i need to call the filter explicitly  to start the poll again? Since in
my Filter I am getting the sequence from the Db always in the accept method.

<route shutdownRunningTask="CompleteCurrentTaskOnly" id="UserCSVToDB" >
		    <from
uri="file:///C:\FS\processing\?delay=3600000&amp;readLock=true&amp;move=C:\FS\complete&amp;filter=#filterDS&amp;charset=utf-8"/>
		      <setHeader headerName="sourcename">
      			<simple>DS</simple>
              </setHeader>
               <setHeader headerName="fileseq">
      			<method ref="DatabaseBean"
method="getSequence(${header.sourcename})" />
              </setHeader>
		    
		    <split streaming="true">
		      <tokenize token="\n"></tokenize>
		      <unmarshal>
		        <csv/>
		      </unmarshal>
		      <log message="The message contains ${body}"/>
		    </split>
		    <to
uri="bean:DatabaseBean?method=updateSequence(${header.sourcename},${header.fileseq})"/>
    </route>





--
View this message in context: http://camel.465427.n5.nabble.com/Camel-file-component-URI-dynamic-options-Filter-query-tp5776861p5777100.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Camel file component URI dynamic options & Filter query

Posted by fxthomas <fe...@gmail.com>.
hello Claus,

Thanks for the Tip. 

I had tried for the point 2) using a eventnotifer class, but the results are
quiet confusing or maybe I am handling some other event  . But i see the
Exchange completed is fired for each message sent. So ite becomes diffcult
to know which is the exact exchaneg complete event.  I will try with a
callback and see if that works fine.

Below is MY event notifier code.

@Override
    public void notify(EventObject event) throws Exception {

	if (event instanceof ExchangeCompletedEvent) {
	    ExchangeCompletedEvent exchangeCompletedEvent =
(ExchangeCompletedEvent) event;
	    Exchange exchange = exchangeCompletedEvent.getExchange();
	    String FileName =
(String)exchange.getProperty(Exchange.FILE_NAME_CONSUMED);
	    System.out.println("EXCHANGE COMPLETED  "+FileName);

	}else if(event instanceof ExchangeCreatedEvent){
	    ExchangeCreatedEvent exchangeCreatedEvent = (ExchangeCreatedEvent)
event;
	    Exchange exchange = exchangeCreatedEvent.getExchange();
	    String FileName = (String)
exchange.getProperty(Exchange.FILE_NAME_CONSUMED);
	    System.out.println("EVENTTTTTTTTTTTT "+FileName);


	}else{
	    System.out.println("EVENT NOt KNOWN  "+event.getClass().getName());
	}

    }


    protected void doStart() throws Exception {
	// filter out unwanted events
	setIgnoreCamelContextEvents(true);
	setIgnoreServiceEvents(true);
	setIgnoreRouteEvents(false);
	setIgnoreExchangeCreatedEvent(false);
	setIgnoreExchangeCompletedEvent(false);
	setIgnoreExchangeFailedEvents(false);
	setIgnoreExchangeRedeliveryEvents(true);
	setIgnoreExchangeSentEvents(false);
    }



The Results On Console.


EVENTTTTTTTTTTTT null
1 CSV Line - printed
EXCHANGE COMPLETED  null

EVENTTTTTTTTTTTT null
2 second CSV line - printed
EXCHANGE COMPLETED  null

EVENT NOt KNOWN  org.apache.camel.management.event.ExchangeSendingEvent
Updating sequence 0
EVENT NOt KNOWN  org.apache.camel.management.event.ExchangeSentEvent
EXCHANGE COMPLETED  null



--
View this message in context: http://camel.465427.n5.nabble.com/Camel-file-component-URI-dynamic-options-Filter-query-tp5776861p5777145.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Camel file component URI dynamic options & Filter query

Posted by Claus Ibsen <cl...@gmail.com>.
On Mon, Feb 1, 2016 at 6:08 PM, fxthomas <fe...@gmail.com> wrote:
> I tried with a new approach it works  atleast for basic condition  . But the
> problem is if there is any file left in the folder which did not match in
> the Run , the route keeps on polling and the filter is called everytime .
>
> 1) Is there any way in which the route can be told to stop pooling after
> subsequent polls which did not result any file processing.
>

You can use a route policy, with sendEmptyMessageWhenIdle=true, and
then detect if its an empty file and stop the route.
And mind you would need to filter the empty file in your route so you
do not process the empty file.

Also you can use the backoff to not poll so often when there is no
files. So it wont poll so often, though its still running.


> 2) There could be a gap in the sequence,  i.e. after 2 , 4 can be the next
> file how can i come to know that the route has finished processing one
> cylce, so that I can increment again in filter and the route will work
> again.

You can add a callback to the exchange which gets called when its done
/ or use event notifier etc.




>
> 3) Incase there is a file les than sequence or any junk file , it should be
> moved to different folder. Since I am using a Filter , not sure if that can
> be done . I can configure a different route to counter this.
>
>





>
>  <route shutdownRunningTask="CompleteCurrentTaskOnly" id="RouteFilter" >
>      <from uri="timer://foo?period=2h"/>
>      <to uri="controlbus:route?routeId=UserCSVToDB&amp;action=start" />
>    </route>
>
>
>     <route shutdownRunningTask="CompleteCurrentTaskOnly" id="UserCSVToDB"
> autoStartup="false">
>                     <from
> uri="file:///C:\FS\processing\?readLock=true&amp;move=C:\FS\complete&amp;filter=#filterDS&amp;charset=utf-8"/>
>
>                       <setHeader headerName="sourcename">
>                         <simple>DS</simple>
>               </setHeader>
>                <setHeader headerName="fileseq">
>                         <method ref="DatabaseBean"
> method="getSequence(${header.sourcename})" />
>               </setHeader>
>
>                     <split streaming="true">
>                       <tokenize token="\n"></tokenize>
>                       <unmarshal>
>                         <csv/>
>                       </unmarshal>
>                       <log message="The message contains ${body}"/>
>                     </split>
>                     <to
> uri="bean:DatabaseBean?method=updateSequence(${header.sourcename},${header.fileseq})"/>
>     </route>
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Camel-file-component-URI-dynamic-options-Filter-query-tp5776861p5777107.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: Camel file component URI dynamic options & Filter query

Posted by fxthomas <fe...@gmail.com>.
I tried with a new approach it works  atleast for basic condition  . But the
problem is if there is any file left in the folder which did not match in
the Run , the route keeps on polling and the filter is called everytime .

1) Is there any way in which the route can be told to stop pooling after
subsequent polls which did not result any file processing.

2) There could be a gap in the sequence,  i.e. after 2 , 4 can be the next
file how can i come to know that the route has finished processing one
cylce, so that I can increment again in filter and the route will work
again.

3) Incase there is a file les than sequence or any junk file , it should be
moved to different folder. Since I am using a Filter , not sure if that can
be done . I can configure a different route to counter this.



 <route shutdownRunningTask="CompleteCurrentTaskOnly" id="RouteFilter" >
     <from uri="timer://foo?period=2h"/>
     <to uri="controlbus:route?routeId=UserCSVToDB&amp;action=start" />
   </route>
 

    <route shutdownRunningTask="CompleteCurrentTaskOnly" id="UserCSVToDB"
autoStartup="false">
		    <from
uri="file:///C:\FS\processing\?readLock=true&amp;move=C:\FS\complete&amp;filter=#filterDS&amp;charset=utf-8"/>
		      
		      <setHeader headerName="sourcename">
      			<simple>DS</simple>
              </setHeader>
               <setHeader headerName="fileseq">
      			<method ref="DatabaseBean"
method="getSequence(${header.sourcename})" />
              </setHeader>
		    
		    <split streaming="true">
		      <tokenize token="\n"></tokenize>
		      <unmarshal>
		        <csv/>
		      </unmarshal>
		      <log message="The message contains ${body}"/>
		    </split>
		    <to
uri="bean:DatabaseBean?method=updateSequence(${header.sourcename},${header.fileseq})"/>
    </route>



--
View this message in context: http://camel.465427.n5.nabble.com/Camel-file-component-URI-dynamic-options-Filter-query-tp5776861p5777107.html
Sent from the Camel - Users mailing list archive at Nabble.com.