Hello,

i have a strange behaviour when I try to consume files from a directory
several times.
I want to copy files to a directory and in a second time, I want to move
these files in another directory.

If I do it one time, everything is fine. But if a execute this a second time
following the first, it blocks.

Here's my main method:
...
        //first time
        Endpoint in = cc.getEndpoint("direct:bla");
        Producer producer = in.createProducer();
        Exchange exchange = producer.createExchange();
        producer.process(exchange);
       
        Thread.sleep(5000);
       
        //second time
        producer = in.createProducer();
        exchange = producer.createExchange();
        producer.process(exchange);
...

and here's the method in a bean that I try to execute:
...
    public void consProd(){
        String saveTo2 = "file:C:\\temp\\dir2";
        String saveTo = "file:C:\\temp\\dir1";
       
        String from = "C:\\temp\\temporaryDir";
        File dir = new File(from);
        String[] fileList = dir.list();
       
        for(String fileName : fileList) {
            ProducerTemplate prod = cc.createProducerTemplate();
            ConsumerTemplate cons = cc.createConsumerTemplate();

            Exchange exchange = cons.receive("file:" + from + "?fileName=" +
                fileName + "&noop=true", 5000);
               
            prod.send(saveTo, exchange);
            cons.doneUoW(exchange);
        }
       
        for(String fileName : fileList) {
            ProducerTemplate prod = cc.createProducerTemplate();
            ConsumerTemplate cons = cc.createConsumerTemplate();
           
            Exchange exchange = cons.receive("file:" + from + "?fileName=" +
                fileName + "&delete=true", 5000);
           
            prod.send(saveTo2, exchange);
            cons.doneUoW(exchange);
        }
    }
...

and my route:
from("direct:bla").bean(prodBean, "consProd");

I first tried with one consumer and one producer for all the operations but
there was a problem with same file names (noop and idempotent). So I decided
to try with creating new consumers and producers every time but it doesn't
change anything.
I do it in a bean because it's a part of a quartz route. What I showed here
is not the final code but a test to reproduce the case. 

I didn't mention it but, obviously, while Thread.sleep(5000), I re-past
files to from dir! So there are the same files again. 

I don't understand the logic. I need to be able to do this for integration
tests.

Could you help me or give me some tips please.

Thanks a lot.

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

Reply via email to