You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by sumatheja <su...@gmail.com> on 2011/05/28 19:55:26 UTC
File Poller
I'm completely new to Apache camel... Please help me with an example for file
polling.... I want to poll a local directory and do some processing.... I
was unable to get much help from web.... Any help is much appreciated.
Thanks in Advance
--
View this message in context: http://camel.465427.n5.nabble.com/File-Poller-tp4435442p4435442.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: File Poller
Posted by AnujK <re...@gmail.com>.
Hi guys, this works, but what if I would like my standalone application to
end gracefully after the camel context has been shutdown without using the
control-c option.
Using this Main.run() approach keeps the VM running forever (even after the
camelcontext) has been shutdown.
Is there a way to end my VM session gracefully?
--
View this message in context: http://camel.465427.n5.nabble.com/File-Poller-tp4435442p4473722.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: File Poller
Posted by sumatheja <su...@gmail.com>.
Thanks Claus .... its working fine now
--
View this message in context: http://camel.465427.n5.nabble.com/File-Poller-tp4435442p4442652.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: File Poller
Posted by Claus Ibsen <cl...@gmail.com>.
On Tue, May 31, 2011 at 5:18 PM, sumatheja <su...@gmail.com> wrote:
> Hi Claus,
> Thanks for the help. But when i try to run my code its throwing
> the following exception
>
> Exception in thread "main" 2011-05-31 20:44:29,313 [Thread-1 ] INFO
> MainSupport$HangupInterceptor - Received hang up - stopping the main
> instance.
> org.apache.camel.CamelException: Cannot find any Camel Context from the
> Application Context. Please check your Application Context setting
> at
Hi it looks like you are using the Main class from camel-spring. And
it expects you define a <camelContext> in the Spring XML file.
If you do not want to do that, eg just start Camel from only Java code
(no Spring) then use the Main class from camel-core.
Its all explained here
http://camel.apache.org/running-camel-standalone-and-have-it-keep-running.html
> org.apache.camel.impl.MainSupport.postProcessContext(MainSupport.java:371)
> at org.apache.camel.spring.Main.doStart(Main.java:144)
> at org.apache.camel.impl.ServiceSupport.start(ServiceSupport.java:67)
> at org.apache.camel.impl.ServiceSupport.start(ServiceSupport.java:54)
> at org.apache.camel.impl.MainSupport.run(MainSupport.java:136)
> at camelinaction.FinalCSVParser.main(FinalCSVParser.java:56)
>
> Given below is my code. Can you please let me know where i'm going wrong??
>
> public class FinalCSVParser {
>
>
> public static void main(String[] args) throws Exception {
>
> Main main = new Main();
> main.enableHangupSupport();
>
> main.setApplicationContextUri("META-INF/spring/camel-context.xml") ;
> main.addRouteBuilder(new RouteBuilder() {
> public void configure() throws Exception {
> from("file:src/data?delay=10000&noop=true")
> .unmarshal().bindy(BindyType.Csv, "camelinaction")
> .process(new Processor(){
> public void process(Exchange exchange) throws
> Exception {
> List listin =
> exchange.getIn().getBody(List.class);
> List<PurchaseOrder> listout = new
> ArrayList<PurchaseOrder>();
> System.out.println(listin.size());
> int i = 0;
> for (i=0; i<listin.size(); i++){
> Map row = (Map) listin.get(i);
> System.out.println(row.size());
>
> listout.add((PurchaseOrder)row.get(PurchaseOrder.class.getName()));
> }
> System.out.println(listout.size());
> exchange.getIn().setBody(listout);
>
> }
>
> })
> .split(body())
> .to("jpa:camelinaction.PurchaseOrder");
>
>
> }
> });
> main.run();
>
> }
> }
>
>
> Thanks in advance.
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/File-Poller-tp4435442p4442309.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
--
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
CamelOne 2011: http://fusesource.com/camelone2011/
Twitter: davsclaus, fusenews
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/
Re: File Poller
Posted by sumatheja <su...@gmail.com>.
Hi Claus,
Thanks for the help. But when i try to run my code its throwing
the following exception
Exception in thread "main" 2011-05-31 20:44:29,313 [Thread-1 ] INFO
MainSupport$HangupInterceptor - Received hang up - stopping the main
instance.
org.apache.camel.CamelException: Cannot find any Camel Context from the
Application Context. Please check your Application Context setting
at
org.apache.camel.impl.MainSupport.postProcessContext(MainSupport.java:371)
at org.apache.camel.spring.Main.doStart(Main.java:144)
at org.apache.camel.impl.ServiceSupport.start(ServiceSupport.java:67)
at org.apache.camel.impl.ServiceSupport.start(ServiceSupport.java:54)
at org.apache.camel.impl.MainSupport.run(MainSupport.java:136)
at camelinaction.FinalCSVParser.main(FinalCSVParser.java:56)
Given below is my code. Can you please let me know where i'm going wrong??
public class FinalCSVParser {
public static void main(String[] args) throws Exception {
Main main = new Main();
main.enableHangupSupport();
main.setApplicationContextUri("META-INF/spring/camel-context.xml") ;
main.addRouteBuilder(new RouteBuilder() {
public void configure() throws Exception {
from("file:src/data?delay=10000&noop=true")
.unmarshal().bindy(BindyType.Csv, "camelinaction")
.process(new Processor(){
public void process(Exchange exchange) throws
Exception {
List listin =
exchange.getIn().getBody(List.class);
List<PurchaseOrder> listout = new
ArrayList<PurchaseOrder>();
System.out.println(listin.size());
int i = 0;
for (i=0; i<listin.size(); i++){
Map row = (Map) listin.get(i);
System.out.println(row.size());
listout.add((PurchaseOrder)row.get(PurchaseOrder.class.getName()));
}
System.out.println(listout.size());
exchange.getIn().setBody(listout);
}
})
.split(body())
.to("jpa:camelinaction.PurchaseOrder");
}
});
main.run();
}
}
Thanks in advance.
--
View this message in context: http://camel.465427.n5.nabble.com/File-Poller-tp4435442p4442309.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: File Poller
Posted by Claus Ibsen <cl...@gmail.com>.
Just use the Main class from camel-spring.
On Sun, May 29, 2011 at 3:21 PM, sumatheja <su...@gmail.com> wrote:
>
> I'm want to use main to start a polling service... presently I'm using
> CamelContext and connecting to a database for that i'm using the followint
> method to create camelcontext
>
> private CamelContext createCamelContext() throws Exception {
> // TODO Auto-generated method stub
> applicationContext = new
> ClassPathXmlApplicationContext("META-INF/spring/camel-context.xml");
> return SpringCamelContext.springCamelContext(applicationContext);
> }
>
>
> But when I use main.run() to start the service how to set this
> ApplicationContext. Or is there any other way of running the polling service
> indefinitely for the route mentioned in the above posts.
>
> Thanks in advance
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/File-Poller-tp4435442p4437053.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
--
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
CamelOne 2011: http://fusesource.com/camelone2011/
Twitter: davsclaus, fusenews
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/
Re: File Poller
Posted by sumatheja <su...@gmail.com>.
I'm want to use main to start a polling service... presently I'm using
CamelContext and connecting to a database for that i'm using the followint
method to create camelcontext
private CamelContext createCamelContext() throws Exception {
// TODO Auto-generated method stub
applicationContext = new
ClassPathXmlApplicationContext("META-INF/spring/camel-context.xml");
return SpringCamelContext.springCamelContext(applicationContext);
}
But when I use main.run() to start the service how to set this
ApplicationContext. Or is there any other way of running the polling service
indefinitely for the route mentioned in the above posts.
Thanks in advance
--
View this message in context: http://camel.465427.n5.nabble.com/File-Poller-tp4435442p4437053.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: File Poller
Posted by sumatheja <su...@gmail.com>.
Thanks so much Stephane... its working fine now....
--
View this message in context: http://camel.465427.n5.nabble.com/File-Poller-tp4435442p4435740.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: File Poller
Posted by Stéphane Deraco <st...@deraco.fr>.
Yes, the file component does polling by default.
How do you run your application? If it is standalone (plain Java), after
having started the camel context, you must make the Thread to sleep
(otherwise the camel context initiates its shutdown).
You can do that with, Thread.sleep after having started the context,
or better by using org.apache.camel.Main or org.apache.camel.spring.Main
class (see
http://camel.apache.org/running-camel-standalone-and-have-it-keep-running.html
)
Stéphane
On Sat, May 28, 2011 at 9:46 PM, sumatheja <su...@gmail.com> wrote:
> You mean to say it does polling by default?? In my case the context is just
> shutting down without polling.... i tried delay option too but same
> result.....
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/File-Poller-tp4435442p4435709.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
Re: File Poller
Posted by sumatheja <su...@gmail.com>.
You mean to say it does polling by default?? In my case the context is just
shutting down without polling.... i tried delay option too but same
result.....
--
View this message in context: http://camel.465427.n5.nabble.com/File-Poller-tp4435442p4435709.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: File Poller
Posted by Stéphane Deraco <st...@deraco.fr>.
Hi Sumatheja,
I think what you need is the "delay" option, not "consumer.delay".
See the Consumer URI Options in http://camel.apache.org/file2.html :
delay (default 500) : Milliseconds before the next poll of the
file/directory
Stéphane
On Sat, May 28, 2011 at 9:12 PM, sumatheja <su...@gmail.com> wrote:
> Hi Tarreq,
> I'm directing the output to another end point everthing other
> than the polling part is working fine.... find the complete route below
>
>
> from("file:src/data?consumer.delay=10000")
> .unmarshal().bindy(BindyType.Csv,
> "camelinaction")
> .to("mock:result");
>
>
> I'm reading a csv file and unmarshalling it.... just want to scan for the
> csv fiules periodically.
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/File-Poller-tp4435442p4435613.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
Re: File Poller
Posted by sumatheja <su...@gmail.com>.
Hi Tarreq,
I'm directing the output to another end point everthing other
than the polling part is working fine.... find the complete route below
from("file:src/data?consumer.delay=10000")
.unmarshal().bindy(BindyType.Csv, "camelinaction")
.to("mock:result");
I'm reading a csv file and unmarshalling it.... just want to scan for the
csv fiules periodically.
--
View this message in context: http://camel.465427.n5.nabble.com/File-Poller-tp4435442p4435613.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: File Poller
Posted by Taariq Levack <ta...@gmail.com>.
I'm not familiar with that option, looks strange, but otherwise you have a consumer. Now to send the files either to another endpoint or process it. The "getting started" link given before should help you further.
Also see http://camel.apache.org/file2.html
Taariq
On 28 May 2011, at 8:40 PM, sumatheja <su...@gmail.com> wrote:
> Thanks for your reply... I went through the pdf... It says the same thing as
> i was trying earlier.... I'm using the following code
>
> from("file:src/data?consumer.delay=10000")
>
> Do I need to add anything else to this endpoint to poll the directory or
> should I add some extra code.
>
> Thanks in advance
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/File-Poller-tp4435442p4435538.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
Re: File Poller
Posted by sumatheja <su...@gmail.com>.
Thanks for your reply... I went through the pdf... It says the same thing as
i was trying earlier.... I'm using the following code
from("file:src/data?consumer.delay=10000")
Do I need to add anything else to this endpoint to poll the directory or
should I add some extra code.
Thanks in advance
--
View this message in context: http://camel.465427.n5.nabble.com/File-Poller-tp4435442p4435538.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: File Poller
Posted by Marcelo Jabali <mj...@fusesource.com>.
The following resources should give you what you need.
http://camel.apache.org/getting-started.html
http://www.manning.com/ibsen/Camel_ch01_update.pdf
Hope this helps,
-Marcelo
On May 28, 2011, at 10:55 AM, sumatheja wrote:
> I'm completely new to Apache camel... Please help me with an example for file
> polling.... I want to poll a local directory and do some processing.... I
> was unable to get much help from web.... Any help is much appreciated.
>
> Thanks in Advance
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/File-Poller-tp4435442p4435442.html
> Sent from the Camel - Users mailing list archive at Nabble.com.