You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Kevin Jackson <fo...@gmail.com> on 2010/02/15 16:38:48 UTC

quartz trigger for ftp consumer

Hi,

I need to use a quartz corn schedule to trigger an ftp consumer

I guess this is a common idiom, but as yet I cannot find any examples
on the wiki or in the archived mailing list

Currently I have:

<camel:route startupOrder="0">
  <camel:from ref="stock-schedule"/>
  <camel:to ref="stock-ftp"/>
  <camel:to ref="stock-file"/>
</camel:route>

which I know is incorrect.  I have looked at

<camel:route startupOrder="0">
  <camel:from ref="stock-schedule"/>
  <camel:enrich ref="stock-ftp"/>
  <camel:to ref="stock-file"/>
</camel:route>

but I know this is also incorrect.

<camel:route startupOrder="0">
  <camel:from ref="stock-schedule"/>
  <camel:from ref="stock-ftp"/> <-- this needs to be a from in my
opinion but I don't know how to achieve this
  <camel:to ref="stock-file"/>
</camel:route>

Thanks,
Kev

Re: quartz trigger for ftp consumer

Posted by "gesberkj@gmail.com" <ge...@gmail.com>.
 from("jpa:com.mycompany.camel.java.model.Person?scheduler=quartz2&scheduler.cron=0/30
* * * * ?&consumeDelete=false&delay=3000&consumeLockEntity=false")
    //.from("quartz2://myGroup/myTimerName?cron=0 0/2 * 1/1 * ? *")
          //  .setHeader(Exchange.FILE_NAME, el("${in.body.userName}.xml"))
    .marshal(jxb)
   // .autoStartup("")
  //.pollEnrich("scheduler=quartz2&scheduler.cron=0 0/2 * 1/1 * ? *")
   
     .to("file:/home/gesb2379/src/data1");


i want to get data from db and store it in a file but gives 


Exception in thread "main" org.apache.camel.FailedToCreateConsumerException:
Failed to create Consumer for endpoint:
jpa://com.mycompany.camel.java.model.Person?consumeDelete=false&consumeLockEntity=false&delay=3000&scheduler=quartz2&scheduler.cron=0%2F30+*+*+*+*+%3F.
Reason: There are 1 scheduler parameters that couldn't be set on the
endpoint. Check the uri if the parameters are spelt correctly and that they
are properties of the endpoint. Unknown parameters=[{cron=0/30 * * * * ?}]
	at
org.apache.camel.impl.ScheduledPollConsumer.doStart(ScheduledPollConsumer.java:433)
	at org.apache.camel.component.jpa.JpaConsumer.doStart(JpaConsumer.java:526)
	at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:61)
	at
org.apache.camel.impl.DefaultCamelContext.startService(DefaultCamelContext.java:3471)
	at
org.apache.camel.impl.DefaultCamelContext.doStartOrResumeRouteConsumers(DefaultCamelContext.java:3788)
	at
org.apache.camel.impl.DefaultCamelContext.doStartRouteConsumers(DefaultCamelContext.java:3724)
	at
org.apache.camel.impl.DefaultCamelContext.safelyStartRouteServices(DefaultCamelContext.java:3644)
	at
org.apache.camel.impl.DefaultCamelContext.doStartOrResumeRoutes(DefaultCamelContext.java:3408)
	at
org.apache.camel.impl.DefaultCamelContext.doStartCamel(DefaultCamelContext.java:3262)
	at
org.apache.camel.impl.DefaultCamelContext.access$000(DefaultCamelContext.java:201)
	at
org.apache.camel.impl.DefaultCamelContext$2.call(DefaultCamelContext.java:3046)
	at
org.apache.camel.impl.DefaultCamelContext$2.call(DefaultCamelContext.java:3042)
	at
org.apache.camel.impl.DefaultCamelContext.doWithDefinedClassLoader(DefaultCamelContext.java:3065)
	at
org.apache.camel.impl.DefaultCamelContext.doStart(DefaultCamelContext.java:3042)
	at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:61)
	at
org.apache.camel.impl.DefaultCamelContext.start(DefaultCamelContext.java:2980)
	at
org.apache.camel.spring.SpringCamelContext.maybeStart(SpringCamelContext.java:275)
	at
org.apache.camel.spring.SpringCamelContext.onApplicationEvent(SpringCamelContext.java:136)
	at
org.apache.camel.spring.CamelContextFactoryBean.onApplicationEvent(CamelContextFactoryBean.java:361)
	at
org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:167)
	at
org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
	at
org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:383)
	at
org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:337)
	at
org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:882)
	at
org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:545)
	at
org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
	at
org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:93)
	at
org.apache.camel.spring.Main.createDefaultApplicationContext(Main.java:222)
	at org.apache.camel.spring.Main.doStart(Main.java:154)
	at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:61)
	at org.apache.camel.main.MainSupport.run(MainSupport.java:168)
	at org.apache.camel.main.MainSupport.run(MainSupport.java:482)
	at com.mycompany.camel.java.jpa.MainApp.main(MainApp.java:17)







--
View this message in context: http://camel.465427.n5.nabble.com/quartz-trigger-for-ftp-consumer-tp473092p5802244.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: quartz trigger for ftp consumer

Posted by Claus Ibsen <cl...@gmail.com>.
On Tue, Jan 25, 2011 at 6:35 PM, Alfred Hiebl <a....@mic-cust.com> wrote:
>
> Hi Claus,
>
> is there a plan date/release for that schduling DSL?
>

Its not in the short term plan.

Most likely in Camel 3.0/3.1.
http://camel.apache.org/camel-30-roadmap.html


> Best regards,
> Alfred
> --
> View this message in context: http://camel.465427.n5.nabble.com/quartz-trigger-for-ftp-consumer-tp473092p3356668.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>



-- 
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/

Re: quartz trigger for ftp consumer

Posted by Alfred Hiebl <a....@mic-cust.com>.
Hi Claus,

is there a plan date/release for that schduling DSL?

Best regards,
Alfred
-- 
View this message in context: http://camel.465427.n5.nabble.com/quartz-trigger-for-ftp-consumer-tp473092p3356668.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: quartz trigger for ftp consumer

Posted by Claus Ibsen <cl...@gmail.com>.
On Tue, Feb 16, 2010 at 11:20 AM, Kevin Jackson <fo...@gmail.com> wrote:
> Hi Claus,
>
>> In the future we will add a scheduled DSL to Camel so you can schedule
>> routes to be started using a nice DSL syntax which supports CRON and
>> regular timer delays etc. If we had that in place your use case would
>> be easy.
>
> That sounds great!  Do you want a hand with the code, I'm happy to
> contribute to something that we really need here.
>

We love contributions. The problem is mostly that camel-core need to
work with a CRON library of choice, such as quartz.
So its probably a little work in camel-core to detect whether
camel-quartz is in the classpath and being able to leverage some logic
in there to create the quartz scheduler and have it fire a task based
on the cron setting. Then that logic must work together with the
ScheduledPollConsumer which is the stuff that currently is in use by
ftp/file components etc.

Maybe the CRON library should be pluggable so we can leverage Spring
CRON in 3.0 and/or the new CRON library in ActiveMQ 5.4.
I dont fancy writing a CRON library from beginning :)



> Do you have any suggestions for a workaround I can use now until this
> new DSL is available?
>

You could probably use a custom PollingConsumerPollStrategy and only
return true in begin if the CRON job had recently fired.
eg use some shared flag which you set to true from the CRON job, and
then in the poll strategy you check this flag. And if it was true you
can go ahead, and then set the flag to false.
http://camel.apache.org/polling-consumer.html


> I'm think we could just use the consumer.delay and
> consumer.initialDelay to achieve nearly the same functionality but
> with harder to read config.
>
> My only concern is
> a daily schedule becomes consumer.deplay=86400000 - does the ftp
> component use ints or longs to store the number of miliseconds...
>

Yeah they should be longs for millis

    private long initialDelay = 1000;
    private long delay = 500;

There is also a timeunit
    private TimeUnit timeUnit = TimeUnit.MILLISECONDS;

But that is not easily settable from endpoint URI


> Thanks for the help so far,
>
> Kev
>



-- 
Claus Ibsen
Apache Camel Committer

Author of Camel in Action: http://www.manning.com/ibsen/
Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus

Re: quartz trigger for ftp consumer

Posted by Kevin Jackson <fo...@gmail.com>.
Hi Claus,

> In the future we will add a scheduled DSL to Camel so you can schedule
> routes to be started using a nice DSL syntax which supports CRON and
> regular timer delays etc. If we had that in place your use case would
> be easy.

That sounds great!  Do you want a hand with the code, I'm happy to
contribute to something that we really need here.

Do you have any suggestions for a workaround I can use now until this
new DSL is available?

I'm think we could just use the consumer.delay and
consumer.initialDelay to achieve nearly the same functionality but
with harder to read config.

My only concern is
a daily schedule becomes consumer.deplay=86400000 - does the ftp
component use ints or longs to store the number of miliseconds...

Thanks for the help so far,

Kev

Re: quartz trigger for ftp consumer

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

In the future we will add a scheduled DSL to Camel so you can schedule
routes to be started using a nice DSL syntax which supports CRON and
regular timer delays etc. If we had that in place your use case would
be easy.



On Tue, Feb 16, 2010 at 9:58 AM, Kevin Jackson <fo...@gmail.com> wrote:
> Hi,
>
>> http://camel.apache.org/content-enricher.html
>>
>> There is a pollEnrich you can use in the DSL
>
> I have tried this but the ftp connection is downloading the files
> independently of the event fired from quartz.
>
> <camel:route id="download" startupOrder="3">
>  <camel:from ref="schedule"/>
>  <camel:setBody><camel:constant></camel:constant></camel:setBody>
>  <camel:pollEnrich ref="ftp" timeout="-1"/>
>  <camel:to ref="file"/>
> </camel:route>
>
> My understanding of this is that quartz creates an event (or message
> in Java parlance) which triggers the pollEnrich to consume the data
> from the ftp endpoint and write this out to the file
>
> My ftp endpoint is configured as:
>
> <endpoint id="ftp"
>
> uri="ftp://@{ftp.user}@@{ftp.server}/Avail13?password=@{ftp.password}&amp;noop=false&amp;idempotent=true&amp;idempotentRepository=#fileStore&amp;localWorkDirectory=/tmp"/>
>
> Interestingly with pollEnrich, the #fileStore isn't being updated
> whereas with a simple <camel:from ref="ftp"/> it is
>
> I'm not sure that Content Enrich is the EIP I'm after, I just want to
> trigger the download/consumption of a file from ftp on a cron schedule
>
> Kev
>



-- 
Claus Ibsen
Apache Camel Committer

Author of Camel in Action: http://www.manning.com/ibsen/
Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus

Re: quartz trigger for ftp consumer

Posted by Kevin Jackson <fo...@gmail.com>.
Hi,

> http://camel.apache.org/content-enricher.html
>
> There is a pollEnrich you can use in the DSL

I have tried this but the ftp connection is downloading the files
independently of the event fired from quartz.

<camel:route id="download" startupOrder="3">
  <camel:from ref="schedule"/>
  <camel:setBody><camel:constant></camel:constant></camel:setBody>
  <camel:pollEnrich ref="ftp" timeout="-1"/>
  <camel:to ref="file"/>
</camel:route>

My understanding of this is that quartz creates an event (or message
in Java parlance) which triggers the pollEnrich to consume the data
from the ftp endpoint and write this out to the file

My ftp endpoint is configured as:

<endpoint id="ftp"

uri="ftp://@{ftp.user}@@{ftp.server}/Avail13?password=@{ftp.password}&amp;noop=false&amp;idempotent=true&amp;idempotentRepository=#fileStore&amp;localWorkDirectory=/tmp"/>

Interestingly with pollEnrich, the #fileStore isn't being updated
whereas with a simple <camel:from ref="ftp"/> it is

I'm not sure that Content Enrich is the EIP I'm after, I just want to
trigger the download/consumption of a file from ftp on a cron schedule

Kev

Re: quartz trigger for ftp consumer

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

You can use content enricher EIP
http://camel.apache.org/content-enricher.html

There is a pollEnrich you can use in the DSL


On Mon, Feb 15, 2010 at 4:38 PM, Kevin Jackson <fo...@gmail.com> wrote:
> Hi,
>
> I need to use a quartz corn schedule to trigger an ftp consumer
>
> I guess this is a common idiom, but as yet I cannot find any examples
> on the wiki or in the archived mailing list
>
> Currently I have:
>
> <camel:route startupOrder="0">
>  <camel:from ref="stock-schedule"/>
>  <camel:to ref="stock-ftp"/>
>  <camel:to ref="stock-file"/>
> </camel:route>
>
> which I know is incorrect.  I have looked at
>
> <camel:route startupOrder="0">
>  <camel:from ref="stock-schedule"/>
>  <camel:enrich ref="stock-ftp"/>
>  <camel:to ref="stock-file"/>
> </camel:route>
>
> but I know this is also incorrect.
>
> <camel:route startupOrder="0">
>  <camel:from ref="stock-schedule"/>
>  <camel:from ref="stock-ftp"/> <-- this needs to be a from in my
> opinion but I don't know how to achieve this
>  <camel:to ref="stock-file"/>
> </camel:route>
>
> Thanks,
> Kev
>



-- 
Claus Ibsen
Apache Camel Committer

Author of Camel in Action: http://www.manning.com/ibsen/
Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus