You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by raphael <ra...@gmail.com> on 2012/07/02 12:08:47 UTC

File consumer event based (not polling)

Hi,
I'd like to have a File consumer endpoint, but not scheduled on a polling
mechanism.
It would be triggered through a event driven consumer (JMS message for
instance).
Basically, I just want to be able to decide when my file consumer must read
files in the directory.

I've looked in the EventDrivenPollingConsumer, but it seems the FileConsumer
is completely linked with the ScheduledPollConsumer.

Any way to achieve this ?

Thanks a lot.
Raphael. 

--
View this message in context: http://camel.465427.n5.nabble.com/File-consumer-event-based-not-polling-tp5715349.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: File consumer event based (not polling)

Posted by raphael <ra...@gmail.com>.
Of course, i'm pretty sure there are a lot of way to do it ...

Issue is I don't want to crack to much the Camel framework... and just want
to rely on standard API.

Thanks.

--
View this message in context: http://camel.465427.n5.nabble.com/File-consumer-event-based-not-polling-tp5715349p5715358.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: File consumer event based (not polling)

Posted by thomas barker <th...@gmail.com>.
The way I proposed does not take much effort, especially if you are using
groovy (a little more if you are using Java).  The solution is deep enough
into the api that some maintenance might be required to make sure it works
with ongoing camel upgrades.  If you really dont want to go deeper than
RouteBuilder.configure() I would use the suggestions above.  Mine has the
benefit of working with camel's entire file library (file, sftp, ftp, etc),
and if need be any other scheduled polling consumers that should only run
once.

If you are just using files mine is probably overkill, just use a bean or
pollenrich.  I originally wrote this code to deal with sftp, but I use it
for file as well.

If you want the code I am happy to find it at some point.

On Mon, Jul 2, 2012 at 10:28 AM, thomas barker <th...@gmail.com>wrote:

> I have done this before, it may take me a bit to find the code.  I think
> you accomplish it by doing the following:
>
> 1.  Override the from(String) method in RouteBuilder
> 2.  Use getContext().getEndpoint(uri) to get the endpoint, if the endpoint
> is not a scheduledpollingendpoint then do super.from(uri) otherwise continue
> 3.  create a wrapping endpoint and wrapping consumer to wrap a scheduled
> endpoint and a scheduled polling consumer
>
>    - for the doStart method of the wrapping consumer call
>    wrappedConsumer.run(), this will do only one poll and the doStart will not
>    end till the poll is done
>
> 4.  return super.from(wrappedEndpoint) in the overridden method
>
> If I remember right, I think there are some issues if the wrapped consumer
> is a RemoteFileConsumer, but this works pretty well.  I will try to put
> this together in a groovy class soon to help you out.
>
>
> On Mon, Jul 2, 2012 at 10:17 AM, raphael <ra...@gmail.com>wrote:
>
>> OK, it's working by transforming the body in File(filename).
>>
>> But in that scenario, I lost all the features of the file component,
>> right ?
>> (like move option for example).
>>
>> --
>> View this message in context:
>> http://camel.465427.n5.nabble.com/File-consumer-event-based-not-polling-tp5715349p5715355.html
>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>
>
>

Re: File consumer event based (not polling)

Posted by thomas barker <th...@gmail.com>.
I have done this before, it may take me a bit to find the code.  I think
you accomplish it by doing the following:

1.  Override the from(String) method in RouteBuilder
2.  Use getContext().getEndpoint(uri) to get the endpoint, if the endpoint
is not a scheduledpollingendpoint then do super.from(uri) otherwise continue
3.  create a wrapping endpoint and wrapping consumer to wrap a scheduled
endpoint and a scheduled polling consumer

   - for the doStart method of the wrapping consumer call
   wrappedConsumer.run(), this will do only one poll and the doStart will not
   end till the poll is done

4.  return super.from(wrappedEndpoint) in the overridden method

If I remember right, I think there are some issues if the wrapped consumer
is a RemoteFileConsumer, but this works pretty well.  I will try to put
this together in a groovy class soon to help you out.


On Mon, Jul 2, 2012 at 10:17 AM, raphael <ra...@gmail.com>wrote:

> OK, it's working by transforming the body in File(filename).
>
> But in that scenario, I lost all the features of the file component, right
> ?
> (like move option for example).
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/File-consumer-event-based-not-polling-tp5715349p5715355.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>

Re: File consumer event based (not polling)

Posted by Claus Ibsen <cl...@gmail.com>.
On Mon, Jul 2, 2012 at 4:17 PM, raphael <ra...@gmail.com> wrote:
> OK, it's working by transforming the body in File(filename).
>
> But in that scenario, I lost all the features of the file component, right ?
> (like move option for example).
>

Yes you do, you can delete/move the file yourself.
Or you would need to use either a route policy for a route, or use a
consumer template from a java bean.
And make sure to read the javadoc, as there is a done UoW method you
may need to use etc.



> --
> View this message in context: http://camel.465427.n5.nabble.com/File-consumer-event-based-not-polling-tp5715349p5715355.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, fusenews
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen

Re: File consumer event based (not polling)

Posted by raphael <ra...@gmail.com>.
OK, it's working by transforming the body in File(filename).

But in that scenario, I lost all the features of the file component, right ?
(like move option for example).

--
View this message in context: http://camel.465427.n5.nabble.com/File-consumer-event-based-not-polling-tp5715349p5715355.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: File consumer event based (not polling)

Posted by Claus Ibsen <cl...@gmail.com>.
On Mon, Jul 2, 2012 at 2:10 PM, raphael <ra...@gmail.com> wrote:
> Hi,
>
> Actually, this doesn't fit exactly my needs.
>
> I just want to read the filename that I receive in my JMS message...
> I've seen all the discussions about the PollEnrich API ..
>

Just set the message body to a java.io.File to read the file




> So, just wandering how I can achieve this, according that I cannot pass any
> args to pollEnrich.
>
> Thanks.
> Raph.
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/File-consumer-event-based-not-polling-tp5715349p5715353.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, fusenews
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen

Re: File consumer event based (not polling)

Posted by raphael <ra...@gmail.com>.
Hi,

Actually, this doesn't fit exactly my needs.

I just want to read the filename that I receive in my JMS message... 
I've seen all the discussions about the PollEnrich API ..

So, just wandering how I can achieve this, according that I cannot pass any
args to pollEnrich.

Thanks.
Raph.

--
View this message in context: http://camel.465427.n5.nabble.com/File-consumer-event-based-not-polling-tp5715349p5715353.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: File consumer event based (not polling)

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

Yeah you can associate a route with a route policy
http://camel.apache.org/routepolicy.html

And then trigger/control when the file route should be running.



On Mon, Jul 2, 2012 at 1:06 PM, Pontus Ullgren <ul...@gmail.com> wrote:
> Hello,
>
> I see two options for this (there are probably more).
>
> You can use content enricher (see the bottom of
> http://camel.apache.org/content-enricher.html ).
> from("direct:start")
>   .pollEnrich("file:inbox)
>   .to("direct:result");
>
> If I remember correctly the potential problem here is that the
> pollEnrich will only fetch _one_ file and not all files in the
> directory, which is the normal case for a file consumer endpoint.
>
> So another way would be to have a route that starts with
> from("file:inbox") and have it not start by default. Then create a
> helper route that listen for JMS messages and on reception start the
> first route.
> Combine this with the sendEmptyMessageWhenIdle option on the file
> endpoint and you can stop the first route when there are no more
> files, which is when a empty poll occurs.
>
> Best regards
> Pontus Ullgren
>
>
>
>
>
>
>
> On Mon, Jul 2, 2012 at 12:08 PM, raphael <ra...@gmail.com> wrote:
>> Hi,
>> I'd like to have a File consumer endpoint, but not scheduled on a polling
>> mechanism.
>> It would be triggered through a event driven consumer (JMS message for
>> instance).
>> Basically, I just want to be able to decide when my file consumer must read
>> files in the directory.
>>
>> I've looked in the EventDrivenPollingConsumer, but it seems the FileConsumer
>> is completely linked with the ScheduledPollConsumer.
>>
>> Any way to achieve this ?
>>
>> Thanks a lot.
>> Raphael.
>>
>> --
>> View this message in context: http://camel.465427.n5.nabble.com/File-consumer-event-based-not-polling-tp5715349.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, fusenews
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen

Re: File consumer event based (not polling)

Posted by Pontus Ullgren <ul...@gmail.com>.
Hello,

I see two options for this (there are probably more).

You can use content enricher (see the bottom of
http://camel.apache.org/content-enricher.html ).
from("direct:start")
  .pollEnrich("file:inbox)
  .to("direct:result");

If I remember correctly the potential problem here is that the
pollEnrich will only fetch _one_ file and not all files in the
directory, which is the normal case for a file consumer endpoint.

So another way would be to have a route that starts with
from("file:inbox") and have it not start by default. Then create a
helper route that listen for JMS messages and on reception start the
first route.
Combine this with the sendEmptyMessageWhenIdle option on the file
endpoint and you can stop the first route when there are no more
files, which is when a empty poll occurs.

Best regards
Pontus Ullgren







On Mon, Jul 2, 2012 at 12:08 PM, raphael <ra...@gmail.com> wrote:
> Hi,
> I'd like to have a File consumer endpoint, but not scheduled on a polling
> mechanism.
> It would be triggered through a event driven consumer (JMS message for
> instance).
> Basically, I just want to be able to decide when my file consumer must read
> files in the directory.
>
> I've looked in the EventDrivenPollingConsumer, but it seems the FileConsumer
> is completely linked with the ScheduledPollConsumer.
>
> Any way to achieve this ?
>
> Thanks a lot.
> Raphael.
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/File-consumer-event-based-not-polling-tp5715349.html
> Sent from the Camel - Users mailing list archive at Nabble.com.