You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by ebinsingh <eb...@VerizonWireless.com> on 2011/10/06 16:13:09 UTC

Move does not work with file polling

Hi,

I am having trouble moving a file to a back up location after it's consumed
and it's contents sent to a queue.

I am new to Camle world and exploring it. Below is the code am using.

*Spring config:*

<bean id="routeProperties"
class="com.verizon.learn.camel.utils.RoutingProperties">
		<constructor-arg
index="0"><value>file:C:\\camelProject\\data\\inbox?move=C:\\camelProject\\data\\inbox\\bkp</value></constructor-arg>
		<constructor-arg
index="1"><value>file:C:\\camelProject\\data\\outbox\\bkp</value></constructor-arg>
		<constructor-arg
index="2"><value>jms:queue:test_queue</value></constructor-arg>
	</bean>


Code snippet:

			System.out.println("Starting Polloer: "+consumerEndpoint);
			PollingConsumer consumer = consumerEndpoint.createPollingConsumer();
			Producer producer = targetEndpoint.createProducer();
			consumer.start();
			while(true){
				Exchange consumerX = consumer.receive(timeout);
				while(consumerX != null){
					System.out.println("Received message: " + consumerX.getIn().getBody());
					Exchange newExchange = producer.createExchange(consumerX);
					newExchange.getIn().setBody(consumerX.getIn().getBody());
					newExchange.getIn().setHeaders(consumerX.getIn().getHeaders());
					producer.process(newExchange);
					
					consumerX = consumer.receive(timeout);
				}
				Thread.sleep(1000);
			}
		}catch(Exception ex){
			ex.printStackTrace();
		}

--
View this message in context: http://camel.465427.n5.nabble.com/Move-does-not-work-with-file-polling-tp4876472p4876472.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Move does not work with file polling

Posted by Brendan Long <br...@realgo.com>.
On 2011-10-10 1:19 PM, ebinsingh wrote:
>         context.addRoutes(new RouteBuilder() {
>             public void configure() {
>             
> from("quartz://myTimer?trigger.repeatInterval=2000&trigger.repeatCount=-1")
>                 .setBody().simple("I was fired at ${header.fireTime}")
>                 .to("jms:queue:test_request_1");
>             }
>         });
>
> rom the Camel - Users mailing list archive at Nabble.com.
Any reason you're not just using a timer
<https://camel.apache.org/timer.html> directly?

from("timer:myTimer?period=2000&fixedRate=true")

Re: Move does not work with file polling

Posted by ebinsingh <eb...@VerizonWireless.com>.
Appreciate your help.

For some reason each os the polling consumers poll for few seconds and then
terminate.

        context.addRoutes(new RouteBuilder() {
            public void configure() {
            
from("quartz://myTimer?trigger.repeatInterval=2000&trigger.repeatCount=-1")
                .setBody().simple("I was fired at ${header.fireTime}")
                .to("jms:queue:test_request_1");
            }
        });

I thought this would keep running, but the above route terminates after
sending out 3 messages with 2 seconds interval.

I want this to keep running until I kill the process.

I know am missing something, but am not able to figure that out.

--
View this message in context: http://camel.465427.n5.nabble.com/Move-does-not-work-with-file-polling-tp4876472p4889423.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Move does not work with file polling

Posted by Taariq Levack <ta...@gmail.com>.
Hi

The File consumer will poll at regular intervals, default half a second.
If you use routes like Claus mentioned then you may have these 2 routes for what you described.

from("file:someDir").to("seda:foo");

from("seda:foo").multicast().to("seda:bar", "file:someOtherDir");

I've left out the route for "seda:bar", and you could multicast from the first endpoint for the same effect but I stuck to the scenario you described.

Taariq

On 10 Oct 2011, at 8:30 PM, ebinsingh <eb...@VerizonWireless.com> wrote:

> Thanks a lot. My main concern is how to implement endless polling on a
> directory for files. 
> Not quite understanding the behind work of Camel PlooingConsumer. 
> I tried various ways but, the process terminates as soon as the current set
> of files have been read and processed.
> 
> Appreciate your help.
> 
> --
> View this message in context: http://camel.465427.n5.nabble.com/Move-does-not-work-with-file-polling-tp4876472p4889193.html
> Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Move does not work with file polling

Posted by ebinsingh <eb...@VerizonWireless.com>.
Thanks a lot. My main concern is how to implement endless polling on a
directory for files. 
Not quite understanding the behind work of Camel PlooingConsumer. 
I tried various ways but, the process terminates as soon as the current set
of files have been read and processed.

Appreciate your help.

--
View this message in context: http://camel.465427.n5.nabble.com/Move-does-not-work-with-file-polling-tp4876472p4889193.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Move does not work with file polling

Posted by ebinsingh <eb...@VerizonWireless.com>.
Am trying to play around with Camel and this is my first project using it.

The problem am trying to resolve is,

1.	Poll a particular directory for files (This should be running all the
time).
2.	Convert them into Messages and write them to a SEDA (In-memory queue)
3.	Read from the above queue and write to a different queue and also convert
the message into a file and write to a different location.

I am looking for a way to pipeline all of the above.

If you have an example or a reference handy, please pass it on


--
View this message in context: http://camel.465427.n5.nabble.com/Move-does-not-work-with-file-polling-tp4876472p4888954.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Move does not work with file polling

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

You are doing a bit low level coding by creating producer/consumer etc.
Often people just use routes.

Anyway the problem is when you do like this, you need to trigger the
done of the exchange, which will
cause the file to be moved.

See the javadoc for PollingConsumer

/**
 * Represents a <a
 * href="http://camel.apache.org/polling-consumer.html">Polling
 * Consumer</a> where the caller polls for messages when it is ready.
 * <p/>
 * When you are done with the returned {@link Exchange} you must
ensure to invoke
 * {@link org.apache.camel.spi.UnitOfWork#done(Exchange)} to signal to
Camel that the {@link Exchange} is done.
 * <p/>
 * This is needed to ensure any {@link
org.apache.camel.spi.Synchronization} works is being executed.
 * For example if you consumed from a file endpoint, then the consumed
file is only moved/delete when
 * you done the {@link Exchange}.
 *
 * @version
 */

You can do this something like

consumerX.getUnitOfWork().done(consumerX);



On Thu, Oct 6, 2011 at 4:13 PM, ebinsingh
<eb...@verizonwireless.com> wrote:
> Hi,
>
> I am having trouble moving a file to a back up location after it's consumed
> and it's contents sent to a queue.
>
> I am new to Camle world and exploring it. Below is the code am using.
>
> *Spring config:*
>
> <bean id="routeProperties"
> class="com.verizon.learn.camel.utils.RoutingProperties">
>                <constructor-arg
> index="0"><value>file:C:\\camelProject\\data\\inbox?move=C:\\camelProject\\data\\inbox\\bkp</value></constructor-arg>
>                <constructor-arg
> index="1"><value>file:C:\\camelProject\\data\\outbox\\bkp</value></constructor-arg>
>                <constructor-arg
> index="2"><value>jms:queue:test_queue</value></constructor-arg>
>        </bean>
>
>
> Code snippet:
>
>                        System.out.println("Starting Polloer: "+consumerEndpoint);
>                        PollingConsumer consumer = consumerEndpoint.createPollingConsumer();
>                        Producer producer = targetEndpoint.createProducer();
>                        consumer.start();
>                        while(true){
>                                Exchange consumerX = consumer.receive(timeout);
>                                while(consumerX != null){
>                                        System.out.println("Received message: " + consumerX.getIn().getBody());
>                                        Exchange newExchange = producer.createExchange(consumerX);
>                                        newExchange.getIn().setBody(consumerX.getIn().getBody());
>                                        newExchange.getIn().setHeaders(consumerX.getIn().getHeaders());
>                                        producer.process(newExchange);
>
>                                        consumerX = consumer.receive(timeout);
>                                }
>                                Thread.sleep(1000);
>                        }
>                }catch(Exception ex){
>                        ex.printStackTrace();
>                }
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Move-does-not-work-with-file-polling-tp4876472p4876472.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.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/