Apache camel Apache camel文件组件不移动文件

Apache camel Apache camel文件组件不移动文件,apache-camel,Apache Camel,我正在使用ApacheCamel 2.12.1创建一个路由,然后在本地目录中移动一些文件,示例运行良好,但文件从未移动,这是该类的代码 public class MoveFilesTest { private static final Log LOG = LogFactory.getLog(MoveFilesTest.class); public static void main(String args[]) throws Exception { LOG.deb

我正在使用ApacheCamel 2.12.1创建一个路由,然后在本地目录中移动一些文件,示例运行良好,但文件从未移动,这是该类的代码

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();

    }
}
请注意,这段代码只是为了工作,现在我正在使用MacOSX10.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

CamelContext.start
不会阻塞,因此基本上是启动上下文,然后立即停止它。您需要等待或阻止某些内容,直到上下文停止。您可以参考一些方法来执行此操作。

CamelContext.start
不会阻塞,因此基本上是启动上下文,然后立即停止它。您需要等待或阻止某些内容,直到上下文停止。您可以参考一些方法来执行此操作。

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

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


有一个链接:

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

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


有一个链接:

我也遇到了类似的问题,但这与streamCaching()设置不正确有关,因此下面的代码失败了

    context.getStreamCachingStrategy().setSpoolDirectory(spoolDirectory);
    from(uri.toString()).streamCaching().to(destination);
我直接在CamelContext上设置流,这就解决了问题

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

我也遇到了类似的问题,但这与streamCaching()设置不正确有关,因此下面的代码失败了

    context.getStreamCachingStrategy().setSpoolDirectory(spoolDirectory);
    from(uri.toString()).streamCaching().to(destination);
我直接在CamelContext上设置流,这就解决了问题

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

一个好主意是阅读javadoc,比如CamelContext上的API,以及您用来启动Camel的start方法,它解释了为什么:一个好主意是阅读javadoc,比如CamelContext上的API,以及您用来启动Camel的start方法,它解释了为什么:它工作得很好,谢谢,现在我将尝试将它集成到我的项目中。它工作得很好,谢谢,现在我将尝试将其集成到我的项目中。