You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Alex Soto <al...@envieta.com> on 2016/08/16 18:39:36 UTC

poll enrich and file endpoint

Hello,

I am experiencing erratic results when using the Poll Enrich with a static file.
The file is static in the sense that it never changes, so I am setting both the noop=true and the idempotent=false.
Basically I need to be able to serve this same files for ever, and not move it or deleted it.  

My route sets the body with the file name, then it continues with:

<pollEnrich timeout="5000">
   <simple>file:{{env:HOME}}/my-dir?noop=true&amp;fileName=${body}&amp;idempotent=false</simple>  
</pollEnrich>

It works a few times, but after this is executed several times (from multiple clients concurrently), the body becomes null, even though, the file is still present in the directory.  
Am I setting the options correctly?  How can this be accomplished?

Best regards,
Alex soto




Re: poll enrich and file endpoint

Posted by Alex Soto <al...@envieta.com>.
Dennis,

In your case, I think you are missing the idempotent option in the File URI.   

Best regards,
Alex soto



> On Aug 18, 2016, at 10:59 AM, Dennis Bohnstedt Hansen <db...@miracle.dk> wrote:
> 
> Hi
> 
> I’m seeing the same problem with pollEnrich, using a dynamic endpoint. I
> send a my route a filename in the message-body, and expect the file content
> as a reply:
> 
> from("direct:getFileContent")
>        .log("Filename : ${body}")
>        .pollEnrich().simple("file:/temp?readLock=none&noop=true&fileName=${body}").aggregationStrategy(new
> BodyOnlyAggregationStrategy()).timeout(5000)
>        .log(“FileContent: ${body}");
> 
> The first thing i experienced, was that i lost my headers, when i did not
> set an aggregation strategy, to my “BodyOnlyAggregationStrategy”, is a
> fairly started out as a fairly simple strategy, that just copied the body
> to the original exchange:
> 
> public Exchange aggregate(Exchange original, Exchange resource) {
>    if (resource != null && resource.getIn() != null) {
>        Object resourceResponse = resource.getIn().getBody();
>        if (original.getPattern().isOutCapable()) {
>            original.getOut().setBody(resourceResponse);
>        } else {
>            original.getIn().setBody(resourceResponse);
>        }
>    }
>    return original;
> }
> 
> 
> The first time i hit my route, everything works just fine, but after that,
> i start waiting for the timeout, and returns null to the
> AggregationStrategy “resource” Exchange. If i do not set a timeout i hangs
> forever…
> 
> Regards
> / Dennis Bohnstedt Hansen
>  Software designer
>  Miracle A/S - www.miracle.dk <http://www.miracleas.dk/>
>  +45 53747254
> 
> 
> On Thu, Aug 18, 2016 at 8:12 AM, Claus Ibsen <cl...@gmail.com> wrote:
> 
>> Its easier to do a message transformation and set the body as a
>> java.io.File
>> 
>> <transform>
>>  <simple type="java.io.File">{{env:HOME}}/my-dir/${body}</simple>
>> </transform>
>> 
>> 
>> On Tue, Aug 16, 2016 at 8:39 PM, Alex Soto <al...@envieta.com> wrote:
>>> Hello,
>>> 
>>> I am experiencing erratic results when using the Poll Enrich with a
>> static file.
>>> The file is static in the sense that it never changes, so I am setting
>> both the noop=true and the idempotent=false.
>>> Basically I need to be able to serve this same files for ever, and not
>> move it or deleted it.
>>> 
>>> My route sets the body with the file name, then it continues with:
>>> 
>>> <pollEnrich timeout="5000">
>>>   <simple>file:{{env:HOME}}/my-dir?noop=true&amp;fileName=${
>> body}&amp;idempotent=false</simple>
>>> </pollEnrich>
>>> 
>>> It works a few times, but after this is executed several times (from
>> multiple clients concurrently), the body becomes null, even though, the
>> file is still present in the directory.
>>> Am I setting the options correctly?  How can this be accomplished?
>>> 
>>> Best regards,
>>> Alex soto
>>> 
>>> 
>>> 
>> 
>> 
>> 
>> --
>> Claus Ibsen
>> -----------------
>> http://davsclaus.com @davsclaus
>> Camel in Action 2: https://www.manning.com/ibsen2
>> 


Re: poll enrich and file endpoint

Posted by Dennis Bohnstedt Hansen <db...@miracle.dk>.
Hi

I’m seeing the same problem with pollEnrich, using a dynamic endpoint. I
send a my route a filename in the message-body, and expect the file content
as a reply:

from("direct:getFileContent")
        .log("Filename : ${body}")
        .pollEnrich().simple("file:/temp?readLock=none&noop=true&fileName=${body}").aggregationStrategy(new
BodyOnlyAggregationStrategy()).timeout(5000)
        .log(“FileContent: ${body}");

The first thing i experienced, was that i lost my headers, when i did not
set an aggregation strategy, to my “BodyOnlyAggregationStrategy”, is a
fairly started out as a fairly simple strategy, that just copied the body
to the original exchange:

public Exchange aggregate(Exchange original, Exchange resource) {
    if (resource != null && resource.getIn() != null) {
        Object resourceResponse = resource.getIn().getBody();
        if (original.getPattern().isOutCapable()) {
            original.getOut().setBody(resourceResponse);
        } else {
            original.getIn().setBody(resourceResponse);
        }
    }
    return original;
}


The first time i hit my route, everything works just fine, but after that,
i start waiting for the timeout, and returns null to the
AggregationStrategy “resource” Exchange. If i do not set a timeout i hangs
forever…

Regards
/ Dennis Bohnstedt Hansen
  Software designer
  Miracle A/S - www.miracle.dk <http://www.miracleas.dk/>
  +45 53747254


On Thu, Aug 18, 2016 at 8:12 AM, Claus Ibsen <cl...@gmail.com> wrote:

> Its easier to do a message transformation and set the body as a
> java.io.File
>
> <transform>
>   <simple type="java.io.File">{{env:HOME}}/my-dir/${body}</simple>
> </transform>
>
>
> On Tue, Aug 16, 2016 at 8:39 PM, Alex Soto <al...@envieta.com> wrote:
> > Hello,
> >
> > I am experiencing erratic results when using the Poll Enrich with a
> static file.
> > The file is static in the sense that it never changes, so I am setting
> both the noop=true and the idempotent=false.
> > Basically I need to be able to serve this same files for ever, and not
> move it or deleted it.
> >
> > My route sets the body with the file name, then it continues with:
> >
> > <pollEnrich timeout="5000">
> >    <simple>file:{{env:HOME}}/my-dir?noop=true&amp;fileName=${
> body}&amp;idempotent=false</simple>
> > </pollEnrich>
> >
> > It works a few times, but after this is executed several times (from
> multiple clients concurrently), the body becomes null, even though, the
> file is still present in the directory.
> > Am I setting the options correctly?  How can this be accomplished?
> >
> > Best regards,
> > Alex soto
> >
> >
> >
>
>
>
> --
> Claus Ibsen
> -----------------
> http://davsclaus.com @davsclaus
> Camel in Action 2: https://www.manning.com/ibsen2
>

Re: poll enrich and file endpoint

Posted by Alex Soto <al...@envieta.com>.
Wow, I didn’t know this was possible.  Nice trick.  

Still the poll consumer seems to be the most intuitive choice if you come from EIP mindset.  I never thought of my route as doing a data transformation, but rather a content enrichment.   Anyway,  I wonder if others will be hit by the same problem where it does not work correctly when used under  high concurrency.

Thank you Claus.

Best regards,
Alex soto



> On Aug 18, 2016, at 2:12 AM, Claus Ibsen <cl...@gmail.com> wrote:
> 
> Its easier to do a message transformation and set the body as a java.io.File
> 
> <transform>
>  <simple type="java.io.File">{{env:HOME}}/my-dir/${body}</simple>
> </transform>
> 
> 
> On Tue, Aug 16, 2016 at 8:39 PM, Alex Soto <al...@envieta.com> wrote:
>> Hello,
>> 
>> I am experiencing erratic results when using the Poll Enrich with a static file.
>> The file is static in the sense that it never changes, so I am setting both the noop=true and the idempotent=false.
>> Basically I need to be able to serve this same files for ever, and not move it or deleted it.
>> 
>> My route sets the body with the file name, then it continues with:
>> 
>> <pollEnrich timeout="5000">
>>   <simple>file:{{env:HOME}}/my-dir?noop=true&amp;fileName=${body}&amp;idempotent=false</simple>
>> </pollEnrich>
>> 
>> It works a few times, but after this is executed several times (from multiple clients concurrently), the body becomes null, even though, the file is still present in the directory.
>> Am I setting the options correctly?  How can this be accomplished?
>> 
>> Best regards,
>> Alex soto
>> 
>> 
>> 
> 
> 
> 
> -- 
> Claus Ibsen
> -----------------
> http://davsclaus.com @davsclaus
> Camel in Action 2: https://www.manning.com/ibsen2


Re: poll enrich and file endpoint

Posted by Claus Ibsen <cl...@gmail.com>.
Its easier to do a message transformation and set the body as a java.io.File

<transform>
  <simple type="java.io.File">{{env:HOME}}/my-dir/${body}</simple>
</transform>


On Tue, Aug 16, 2016 at 8:39 PM, Alex Soto <al...@envieta.com> wrote:
> Hello,
>
> I am experiencing erratic results when using the Poll Enrich with a static file.
> The file is static in the sense that it never changes, so I am setting both the noop=true and the idempotent=false.
> Basically I need to be able to serve this same files for ever, and not move it or deleted it.
>
> My route sets the body with the file name, then it continues with:
>
> <pollEnrich timeout="5000">
>    <simple>file:{{env:HOME}}/my-dir?noop=true&amp;fileName=${body}&amp;idempotent=false</simple>
> </pollEnrich>
>
> It works a few times, but after this is executed several times (from multiple clients concurrently), the body becomes null, even though, the file is still present in the directory.
> Am I setting the options correctly?  How can this be accomplished?
>
> Best regards,
> Alex soto
>
>
>



-- 
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2: https://www.manning.com/ibsen2