Hi Larry,

I decided to make it real, so following a working example for your usecase:

I did take an already existing Camel example [1] and modified it [2]. You
can run the class either directly inside your IDE or through Maven:

mvn exec:java
-Dexec.mainClass=org.apache.camel.example.spring.MyRouteBuilder

And then watch out how the application shuts down after consuming the 2 xml
files under the data folder.

[1] http://camel.apache.org/spring-example.html
[2]
https://svn.apache.org/repos/asf/camel/trunk/examples/camel-example-spring/src/main/java/org/apache/camel/example/spring/MyRouteBuilder.java

And following the modification I made:

package org.apache.camel.example.spring;

import org.apache.camel.Body;
import org.apache.camel.CamelContext;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.spring.Main;

/**
 * A simple example router from a file system to an ActiveMQ queue and then
to a
 * file system
 * 
 * @version
 */
public class MyRouteBuilder extends RouteBuilder {

    static Main main;

    /**
     * Allow this route to be run as an application
     */
    public static void main(String[] args) throws Exception {
        main = new Main();
        main.run(args);
    }

    public void configure() {
        final CamelContext context = getContext();
        final ProducerTemplate template = context.createProducerTemplate();

       
from("file:src/data?sendEmptyMessageWhenIdle=true").routeId("consumingRoute").process(new
Processor() {

            @Override
            public void process(Exchange exchange) throws Exception {
                if (exchange.getIn().getBody() != null) {
                    // let's process the file content
                    template.send("direct:processingRoute", exchange);
                } else {
                    context.getInflightRepository().remove(exchange);
                    main.stop();
                }
            }

        });

        from("direct:processingRoute").bean(new ProcessingBean());

    }

    public static class ProcessingBean {

        public void process(@Body Object body, CamelContext context) {
            String fileContent =
context.getTypeConverter().convertTo(String.class, body);
            System.out.println("Begin of the file content processing: " +
body);

            // do your processing here:
            System.out.println(fileContent);

            System.out.println("End of the file content processing: " +
body);
        }

    }

}


--
View this message in context: 
http://camel.465427.n5.nabble.com/File-consumer-waiting-for-it-to-start-tp5455062p5456068.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Reply via email to