The first one is probably doing a graceful shutdown so it waits until any inflight exchange is complete before it stops. You can decrease the timeout to less than 300 seconds if you want to.
The two approaches do somewhat different things if I am not misstaken. The first one polls an ftp site for some file. It will retrieve files over and over if new files come. The second one just gets a file once and that is it (unless it is invoked again). So it depends on what you want to do. There is also camel proxy to look at if you want something more lightweight. http://camel.apache.org/using-camelproxy.html On Wed, Feb 8, 2017 at 10:14 PM, Christian Brunotte [via Camel] < ml-node+s465427n5793703...@n5.nabble.com> wrote: > Hello > > So I can either create a producer route with > from("ftp://...").converBodyTo(...).to("direct:result") > and use > String s = camel.createConsumerTemplate().receiveBody("direct:result", > String.class); > > or I create a consumer route with > from("direct:getFile").pollEnrich("ftp://...").convertBodyTo(...) > and use > String s = camel.createFluentProducerTemplate() > .to("direct:getFile").request(String.class); > > Is there any difference or preferred style? > > For some reasons, the first one takes 2s whereas the second one finishes > in only 0.02s. The first also gives a warning, even if I explicitly call > consumerTemplate.stop(), why? > "Waiting as there are still 1 inflight and pending exchanges to > complete, timeout in 300 seconds. Inflights per route: [route1 = 1]" > > -christian- > > > Am Wed, 8 Feb 2017 12:03:27 +0100 > schrieb "Condello, Giovanni" <[hidden email] > <http:///user/SendEmail.jtp?type=node&node=5793703&i=0>>: > > > Hi, > > There's no need for two routes, unless your use case is more complex > > than the example you provided. > > > > You can just use something like this: > > > > context.start(); > > > > /* Now camel is ready */ > > > > ProducerTemplate template = context.createProducerTemplate(); > > > > String result = template.requestBody("direct:blah", null, > > String.class); > > > > /* This will block until your route produces something */ > > > > > > context.stop() > > > > > > 2017-02-08 11:57 GMT+01:00 Christian Brunotte <[hidden email] > <http:///user/SendEmail.jtp?type=node&node=5793703&i=1>>: > > > Hello Zoran > > > > > > So what you propose is (in pseudocode): > > > > > > RouteBuilder builder = new RouteBuilder() { > > > from("direct:start") > > > .enrich("file://src/main/resources/inputs/test.txt") > > > ... > > > .to("direct:result"); > > > } > > > > > > CamelContext camel = new DefaultCamelContext(); > > > camel.addRoutes(simpleRoute); > > > camel.start(); > > > camel.createProducer().send("direct:start"); > > > String result = camel.createConsumer().receiveBody("direct:result", > > > String.class); camel.stop(); > > > > > > That would start the Camel Engine but it would wait for a command > > > ("direct:start") before it does anything and then would have to be > > > manually be polled, correct? > > > > > > Best Regards, > > > > > > -christian- > > > > > > Am Wed, 8 Feb 2017 09:41:24 +0100 > > > schrieb Zoran Regvart <[hidden email] > <http:///user/SendEmail.jtp?type=node&node=5793703&i=2>>: > > > > > >> Hi Christian, > > >> bare in mind that you can have control if you use direct > > >> component, so having Camel context/routes started, doesn't mean > > >> that it needs to poll in the background, you can do that on demand, > > >> > > >> HTH, > > >> > > >> zoran > > >> > > >> On Tue, Feb 7, 2017 at 10:56 PM, Christian Brunotte > > >> <[hidden email] > <http:///user/SendEmail.jtp?type=node&node=5793703&i=3>> wrote: > > >> > Hello > > >> > > > >> > I'd like to integrate Apache Camel into an existing project and > > >> > just use some of it's endpoint capabilities (ftp, file, sftp > > >> > etc.) to fetch some files and maybe validate them a bit. > > >> > > > >> > I don't want Camel to act as the main controller that dispatches > > >> > everything in the background. > > >> > > > >> > Is it possible to use Camel in a very simplistic and lean way > > >> > like e.g.: > > >> > > > >> > RouteBuilder simpleRoute = new RouteBuilder() { > > >> > @Override > > >> > public void configure() { > > >> > > > >> > from("file://src/main/resources/inputs/?include=input.*\\.txt&noop=true") > > > >> > .convertBodyTo(String.class) > > >> > .validate(body().regex("...")); > > >> > } > > >> > }; > > >> > > > >> > String result = > > >> > CamelContext.createSimpleConsumerTemplate(simpleRoute).receiveBody(String.class); > > > >> > > > >> > Currently it seems that I still have to add the route to the > > >> > CamelContext, start it, then call my ConsumerTemplate and after > > >> > that stop the context. > > >> > > > >> > Best Regards > > >> > > > >> > -christian- > > >> > > >> > > >> > > > > ------------------------------ > If you reply to this email, your message will be added to the discussion > below: > http://camel.465427.n5.nabble.com/Using-Camel-to-quickly- > execute-just-one-route-tp5793629p5793703.html > To start a new topic under Camel - Users, email > ml-node+s465427n465428...@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/Using-Camel-to-quickly-execute-just-one-route-tp5793629p5793704.html Sent from the Camel - Users mailing list archive at Nabble.com.