Grokbase Groups Camel users May 2015
FAQ
Hi,

I am using polling consumer pattern to read all files in defined directory :

public List<GenericFile> scanFolder(String folder) {
List<GenericFile> result = new ArrayList<GenericFile>();
String endpointUrl = "file:////" + folder +
"?sendEmptyMessageWhenIdle=true&noop=true"
PollingConsumer pConsumer =
camelContext.getEndpoint(endpointUrl).createPollingConsumer();

pConsumer.start();

GenericFile<File> gFile;

  do {
      Exchange ex = pConsumer.receive(SCAN_TIMEOUT);
      gFile = (GenericFile<File>) ex.getIn().getBody();
      if(gFile != null) {
          result.add(gFile);
      }
   } while(gFile != null); //empty message is sent when endpoint is idle

  pConsumer.stop();

}

This works fine but as I am calling this method repeatedly Camel caches all
files in fileRepository (noop=true enforces idempotent=true) and result is
empty. I am using noop=true because this needs to work with read-only
filesystem. Is there a better way how to create 'folder scanner' using
polling consumer pattern which will read full folder content eachtime ?




--
View this message in context: http://camel.465427.n5.nabble.com/repeated-reading-from-read-only-directory-noop-true-idempotent-false-tp5767338.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Search Discussions

  • Claus Ibsen at May 20, 2015 at 5:16 pm
    Hi

    Probably better to just use the java file api to get a list of files

    Something in the order of
    String[] names = new File(dir).listNames();


    On Wed, May 20, 2015 at 5:20 PM, martin.vich wrote:
    Hi,

    I am using polling consumer pattern to read all files in defined directory :

    public List<GenericFile> scanFolder(String folder) {
    List<GenericFile> result = new ArrayList<GenericFile>();
    String endpointUrl = "file:////" + folder +
    "?sendEmptyMessageWhenIdle=true&noop=true"
    PollingConsumer pConsumer =
    camelContext.getEndpoint(endpointUrl).createPollingConsumer();

    pConsumer.start();

    GenericFile<File> gFile;

    do {
    Exchange ex = pConsumer.receive(SCAN_TIMEOUT);
    gFile = (GenericFile<File>) ex.getIn().getBody();
    if(gFile != null) {
    result.add(gFile);
    }
    } while(gFile != null); //empty message is sent when endpoint is idle

    pConsumer.stop();

    }

    This works fine but as I am calling this method repeatedly Camel caches all
    files in fileRepository (noop=true enforces idempotent=true) and result is
    empty. I am using noop=true because this needs to work with read-only
    filesystem. Is there a better way how to create 'folder scanner' using
    polling consumer pattern which will read full folder content eachtime ?




    --
    View this message in context: http://camel.465427.n5.nabble.com/repeated-reading-from-read-only-directory-noop-true-idempotent-false-tp5767338.html
    Sent from the Camel - Users mailing list archive at Nabble.com.


    --
    Claus Ibsen
    -----------------
    Red Hat, Inc.
    Email: cibsen@redhat.com
    Twitter: davsclaus
    Blog: http://davsclaus.com
    Author of Camel in Action: http://www.manning.com/ibsen
    hawtio: http://hawt.io/
    fabric8: http://fabric8.io/

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupusers @
categoriescamel
postedMay 20, '15 at 4:18p
activeMay 20, '15 at 5:16p
posts2
users2
websitecamel.apache.org

2 users in discussion

Claus Ibsen: 1 post Martin.vich: 1 post

People

Translate

site design / logo © 2021 Grokbase