骆驼初体验 [英] Camel first experience
问题描述
我对 Apache Camel 很陌生.我无法让最简单的 Camel 示例工作.代码如下:
I'm very new with Apache Camel. I can't get the simplest Camel example working. Here is the code:
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
目录.我错过了什么?
Both directories exists, in the from
one there is one simple file, helo.txt
. The route starts and Go!
message is displayed but no file was moved to the to
directory. What am I missing?
这是控制台输出.<代码>SLF4J:无法加载类org.slf4j.impl.StaticLoggerBinder".SLF4j:默认为无操作 (NOP) 记录器实现SLF4J:有关更多详细信息,请参阅 http://www.slf4j.org/codes.html#StaticLoggerBinder去吧!
推荐答案
我猜您正在使用 Windows,因为您引用了 Users/.../Desktop
.如果是这种情况,则您的文件语法略有偏差.您应该拥有 file:///Users/Foo/Desktop
而不是 file://Users/Foo/Desktop
.
I'm guessing you're using Windows, since you have references to Users/.../Desktop
. If that's the case, your file syntax is slightly off. Rather than file://Users/Foo/Desktop
, you should have file:///Users/Foo/Desktop
.
您还需要在应用程序终止之前留出足够的时间进行处理.您可以添加一个 Thread.sleep
.请注意,在网络应用程序中,这不会成为问题,因为应用程序会保持运行.
You also need to allow enough time for the processing to occur before the application terminates. You might add a Thread.sleep
. Note that in a web application, this wouldn't be an issue as the app stays running.
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();
}
}
这篇关于骆驼初体验的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!