Apache camel文件组件不移动文件

时间:2013-11-27 23:16:48

标签: apache-camel

我正在使用apache camel 2.12.1创建一个路由,然后在我的本地目录中移动一些文件,exmple运行正常,但文件永远不会被移动,这是该类的代码。

public class MoveFilesTest {
    private static final Log LOG = LogFactory.getLog(MoveFilesTest.class);

    public static void main(String args[]) throws Exception {
        LOG.debug("create CamelContext");
        CamelContext context = new DefaultCamelContext();

        // add our route to the CamelContext
        context.addRoutes(new RouteBuilder() {
            File file = null;
            public void configure() {
                from("file:data/inbox?delay=100&noop=true")
                .process( new Processor() {

                    public void process(Exchange msg) throws Exception {
                        File file = msg.getIn().getBody(File.class);
                        LOG.debug("Processing file: " + file.getName());

                    }
                })

                .to("file:data/outbox").end();
            }
        });

        LOG.debug("start the route and let it do its work");
        context.start();

        context.stop();

    }
}

作为一个注释,这段代码只是为了工作,现在我正在使用mac os x 10.7,这是调试日志。我添加了noop = false和delete = true,但结果是一样的。谢谢

DEBUG [main] (MoveFilesTest.java:24) - create CamelContext
DEBUG [main] (MoveFilesTest.java:45) - start the route and let it do its work
 INFO [main] (DefaultCamelContext.java:1498) - Apache Camel 2.12.1 (CamelContext: camel-1) is starting
 INFO [main] (ManagedManagementStrategy.java:187) - JMX is enabled
 INFO [main] (DefaultTypeConverter.java:50) - Loaded 176 type converters
 INFO [main] (DefaultCamelContext.java:1689) - 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
 INFO [main] (FileEndpoint.java:83) - Endpoint is configured with noop=true so forcing endpoint to be idempotent as well
 INFO [main] (FileEndpoint.java:89) - Using default memory based idempotent repository with cache max size: 1000
 INFO [main] (DefaultCamelContext.java:2183) - Route: route1 started and consuming from: Endpoint[file://data/inbox?delay=100&noop=true]
 INFO [main] (DefaultCamelContext.java:1533) - Total 1 routes, of which 1 is started.
 INFO [main] (DefaultCamelContext.java:1534) - Apache Camel 2.12.1 (CamelContext: camel-1) started in 8.936 seconds
 INFO [main] (DefaultCamelContext.java:1706) - Apache Camel 2.12.1 (CamelContext: camel-1) is shutting down
 INFO [main] (DefaultShutdownStrategy.java:172) - Starting to graceful shutdown 1 routes (timeout 300 seconds)
 INFO [Camel (camel-1) thread #2 - ShutdownTask] (DefaultShutdownStrategy.java:600) - Route: route1 shutdown complete, was consuming from: Endpoint[file://data/inbox?delay=100&noop=true]
 INFO [main] (DefaultShutdownStrategy.java:217) - Graceful shutdown of 1 routes completed in 0 seconds
 INFO [main] (DefaultCamelContext.java:1780) - Apache Camel 2.12.1 (CamelContext: camel-1) uptime 8.953 seconds
 INFO [main] (DefaultCamelContext.java:1781) - Apache Camel 2.12.1 (CamelContext: camel-1) is shutdown in 0.013 seconds

3 个答案:

答案 0 :(得分:4)

是的,你启动Camel并立即停止它。因此,当您将文件放入文件夹时。它不会处理因为骆驼已经停止了。

Camel包含Main实现,以保持Camel在独立应用程序中运行。

有链接:http://camel.apache.org/running-camel-standalone-and-have-it-keep-running.html

答案 1 :(得分:2)

CamelContext.start没有阻止,所以基本上你是在启动上下文然后立即停止它。您需要等待或阻止某些事情,直到上下文停止。您可以参考this thread了解某些方法。

答案 2 :(得分:0)

我有一个类似的问题,但这与streamCaching()没有正确设置,所以下面的代码失败

    context.getStreamCachingStrategy().setSpoolDirectory(spoolDirectory);
    from(uri.toString()).streamCaching().to(destination);

我直接在CamelContext上设置Streaming并解决了问题

    CamelContext context = getContext();
    context.setStreamCaching(true);
    context.getStreamCachingStrategy().setSpoolDirectory(localSpoolDirectory);
    context.getStreamCachingStrategy().setSpoolThreshold(Long.parseLong(spoolThreshold.trim()));
    context.getStreamCachingStrategy().setBufferSize(Integer.parseInt(bufferSize.trim()));
相关问题