user2176499
user2176499

Reputation: 393

Starting with Camel File Component

I have barely started on Camel and I am trying out the file component. I want to process each file in a directory recursively. I tried to chain from("file:") to a processor and I don't understand why it's not working. In the trace, I can see that the camel context started the route.

public static void main(String[] args) throws Exception {
    System.out.println("Starting camel");
    final CamelContext camelContext = new DefaultCamelContext();
    camelContext.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from(
                    "file://Users/abc123/Documents?recursive=true&noop=true&idempotent=true")
                    .process(new Processor() {

                        public void process(Exchange exchange)
                                throws Exception {
                            System.out.println("exchange=" + exchange);
                        }
                    });

        }
    });
    camelContext.setTracing(true);
    camelContext.start();

    Runtime.getRuntime().addShutdownHook(new Thread() {
        public void run() {
            try {
                camelContext.stop();
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
    });

    Thread.currentThread().join();
}

Here's the log trace:

Starting camel
2015-06-03 00:00:59 INFO  DefaultCamelContext - Apache Camel 2.15.2      (CamelContext: camel-1) is starting
2015-06-03 00:00:59 INFO  DefaultCamelContext - Tracing is enabled on CamelContext: camel-1
2015-06-03 00:00:59 INFO  ManagedManagementStrategy - JMX is enabled
2015-06-03 00:00:59 INFO  DefaultTypeConverter - Loaded 182 type converters
2015-06-03 00:00:59 INFO  DefaultCamelContext - AllowUseOriginalMessage is enabled. If access to the original message is not needed, then its recommended to turn this option off as it may improve performance.
2015-06-03 00:00:59 INFO  DefaultCamelContext - StreamCaching is not in use. If using streams then its recommended to enable stream caching. See more details at http://camel.apache.org/stream-caching.html
2015-06-03 00:00:59 INFO  FileEndpoint - Using default memory based idempotent repository with cache max size: 1000
2015-06-03 00:00:59 INFO  DefaultCamelContext - Route: route1 started and consuming from: Endpoint[file://Users/abc123/Documents?idempotent=true&noop=true&recursive=true]
2015-06-03 00:00:59 INFO  DefaultCamelContext - Total 1 routes, of which 1 is started.
2015-06-03 00:00:59 INFO  DefaultCamelContext - Apache Camel 2.15.2 (CamelContext: camel-1) started in 0.422 seconds

Upvotes: 1

Views: 3459

Answers (1)

Dragan Bozanovic
Dragan Bozanovic

Reputation: 23562

Be sure to specify the correct path to the folder. The best way is to specify the absolute path:

"file:/Users/abc123/Documents?recursive=true&noop=true&idempotent=true"

You can use the relative path, but then make sure that it really is the relative path for the current working directory of the application.

Upvotes: 1

Related Questions