2013-11-27 63 views
0

我使用apache骆驼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(); 

    } 
} 

作注,这段代码只是为了工作,现在我工作在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 
+1

一个好主意是阅读的javadoc,如CamelContext的API,并使用启动骆驼start方法,它的问题解释原因:http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/CamelContext.html –

回答

2

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

+0

它工作得很好,谢谢,现在我会尝试将它集成到我的项目。 – OJVM

0

我也有类似的问题,不过这是与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()));