我已经配置了我的路线,如下所示。我没有收到异常,但同时没有输出。
public static void main(String[] args) {
CamelContext camelContext = new DefaultCamelContext();
try {
camelContext.addRoutes(new RouteBuilder() {
public void configure() {
from("direct:foo")
.to("ahc:http://services.odata.org/V2/Northwind/Northwind.svc/")
.to("file:c:/workpro/outbox?fileName=ahc.xml");
}
});
camelContext.start();
}catch (Exception e1) {
}
}
执行后,我应该在 C 盘中创建一个名为 workpro 的文件夹。您认为我定义路线的方式有任何问题吗?
非常感谢, 拉克什
最佳答案
在 from 中使用计时器,如果您只想调用一次,请将其设置为 repeatCount=1
。
以及非阻塞的启动方法 - 我刚刚添加了 sleep 30 秒。但请参阅此常见问题解答以获得更好的方法:http://camel.apache.org/running-camel-standalone-and-have-it-keep-running.html
public static void main(String[] args) {
CamelContext camelContext = new DefaultCamelContext();
try {
camelContext.addRoutes(new RouteBuilder() {
public void configure() {
from("timer:foo?repeatCount=1")
.to("ahc:http://services.odata.org/V2/Northwind/Northwind.svc/")
.to("file:c:/workpro/outbox?fileName=ahc.xml");
}
});
camelContext.start();
Thread.sleep(30000);
camelContext.stop();
}catch (Exception e1) {
}
}
或者您可以使用 direct 来代替计时器,但是您需要向 direct 端点发送一条消息来触发您的路由运行。这一切都记录在 Apache Camel 入门中,例如 http://camel.apache.org/walk-through-an-example.html 。建议新使用 Camel 的用户阅读:http://java.dzone.com/articles/open-source-integration-apache
关于java - 使用 java DSL 创建的路由不会给出路由是否正确执行的任何线索。也使用 apache AHC compoenet 作为组件之一,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29124549/