You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by watcher <pa...@daly.ws> on 2010/02/08 13:51:11 UTC

Polling consumer not deleting file

I'm looking to archive file(s) which are triggered by an jms message.
However it seems to ignore the file option "delete=true" and the file is not
deleted after it is consumed.

<code>
from("activemq:queue:fileArchive").process(new Processor() {
			public void process(final Exchange exchange) throws Exception {

				// Get Header properties
				Message message = (Message) exchange.getIn();
				final String filename = (String) message.getHeader("filename");
				
				// Create file url for polling
				String url =
"file://c://fileserver?delete=true&readLock=rename&fileName=" + filename;
				log.info(url);
				
				Endpoint endpoint = getContext().getEndpoint(url);
				
				PollingConsumer consumer = endpoint.createPollingConsumer();
				consumer.start();
				Exchange pollExchange = consumer.receive();
				consumer.stop();
				exchange.getOut().setBody(pollExchange.getIn().getBody());
				exchange.getOut().setHeader(Exchange.FILE_NAME, filename);
				
			}
		  }).to("file://c://archive");
</code>

I've also tried implementing the pollEnrich with a similar issue.

from("activemq:queue:fileArchive")
		.setHeader(Exchange.FILE_NAME, header("filename"))
		  
.pollEnrich("file://c://fileserver?delete=true&readLock=rename&fileName=" +
header("fileName")).to("file://c://archive");

Camel version 2.1.0
WIndows XP

Any ideas?
-- 
View this message in context: http://old.nabble.com/Polling-consumer-not-deleting-file-tp27499343p27499343.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Polling consumer not deleting file

Posted by Claus Ibsen <cl...@gmail.com>.
On Mon, Feb 8, 2010 at 1:51 PM, watcher <pa...@daly.ws> wrote:
>
> I'm looking to archive file(s) which are triggered by an jms message.
> However it seems to ignore the file option "delete=true" and the file is not
> deleted after it is consumed.
>

The delete operation is done when the Exchange is done to avoid
deleting the file too soon.
And this works out of the box when using from("file:xxx"). When you do
as you do you have to take action
yourself.

You can transfer the on completions from the pollExchange to the
exchange to let the file be deleted when the original
exchange completes. Use the handoverSynchronization method from
UnitOfWork to transfer it from pollExchange to exchange.
There is a getUnitOfWork method on pollExchange.


> <code>
> from("activemq:queue:fileArchive").process(new Processor() {
>                        public void process(final Exchange exchange) throws Exception {
>
>                                // Get Header properties
>                                Message message = (Message) exchange.getIn();
>                                final String filename = (String) message.getHeader("filename");
>
>                                // Create file url for polling
>                                String url =
> "file://c://fileserver?delete=true&readLock=rename&fileName=" + filename;
>                                log.info(url);
>
>                                Endpoint endpoint = getContext().getEndpoint(url);
>
>                                PollingConsumer consumer = endpoint.createPollingConsumer();
>                                consumer.start();
>                                Exchange pollExchange = consumer.receive();
>                                consumer.stop();
>                                exchange.getOut().setBody(pollExchange.getIn().getBody());
>                                exchange.getOut().setHeader(Exchange.FILE_NAME, filename);
>
>                        }
>                  }).to("file://c://archive");
> </code>
>
> I've also tried implementing the pollEnrich with a similar issue.
>
> from("activemq:queue:fileArchive")
>                .setHeader(Exchange.FILE_NAME, header("filename"))
>
> .pollEnrich("file://c://fileserver?delete=true&readLock=rename&fileName=" +
> header("fileName")).to("file://c://archive");
>
> Camel version 2.1.0
> WIndows XP
>
> Any ideas?
> --
> View this message in context: http://old.nabble.com/Polling-consumer-not-deleting-file-tp27499343p27499343.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
>



-- 
Claus Ibsen
Apache Camel Committer

Author of Camel in Action: http://www.manning.com/ibsen/
Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus