问题
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();
}
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?
Edit:
this is the console output.
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:
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
.
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();
}
}
来源:https://stackoverflow.com/questions/26998659/camel-first-experience