骆驼第一次体验

时间:2014-11-18 16:05:03

标签: apache-camel

我对Apache Camel非常陌生。我无法让最简单的Camel示例正常工作。这是代码:

public class CamelFE {
  public static void main(String[] args)  {
    CamelContext cc = new DefaultCamelContext();
    cc.addRoutes(new RouteBuilder() {
      @Override
      public void configure() throws Exception {
        System.out.println("Go!");
        from("file://Users/Foo/Desktop/IN")
        .to("file://Users/Foo/Desktop/OUT");

    });
  }
  cc.start();
  cc.stop();
}

两个目录都存在,from中有一个简单文件helo.txt。路径启动并显示Go!消息,但没有文件移动到to目录。我错过了什么?

编辑: 这是控制台输出。 SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder". SLF4j: Defaulting to no-operation (NOP) logger implementation SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details Go!

1 个答案:

答案 0 :(得分:1)

我猜你正在使用Windows,因为你引用了Users/.../Desktop。如果是这种情况,那么您的文件语法略有偏差。而不是file://Users/Foo/Desktop,您应该file:///Users/Foo/Desktop

您还需要在应用程序终止之前留出足够的时间进行处理。您可以添加Thread.sleep。请注意,在Web应用程序中,当应用程序保持运行时,这不会成为问题。

public class CamelFE {
    public static void main(String[] args) throws Exception {
        CamelContext cc = new DefaultCamelContext();
        cc.addRoutes(new RouteBuilder()
        {

            @Override
            public void configure() throws Exception {
                System.out.println("Go!");
                from("file:///Users/Foo/Desktop/IN").to("file:///Users/Foo/Desktop/OUT");
            }
        });

        cc.start();
        Thread.sleep(10000);
        cc.stop();
    }
}