Apache camel 骆驼找不到”;sftp“;注册表中的组件并关闭
我正在使用camel sftp组件将文件上载到sftp服务器。 代码很简单:Apache camel 骆驼找不到”;sftp“;注册表中的组件并关闭,apache-camel,apache-karaf,Apache Camel,Apache Karaf,我正在使用camel sftp组件将文件上载到sftp服务器。 代码很简单: File source = new File(path); final String sftpUri = "sftp://" + userId + "@" + serverAddress + "/" + remoteDirectory+"?password="+pwd; CamelContext context = new DefaultCamelContext(); context.addRoutes(new Ro
File source = new File(path);
final String sftpUri = "sftp://" + userId + "@" + serverAddress + "/" + remoteDirectory+"?password="+pwd;
CamelContext context = new DefaultCamelContext();
context.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("file:/" + path).to(sftpUri);
}
});
context.start();
Thread.sleep(10000);
context.stop();
但是,camel在查找sftp组件时遇到问题。激活其投诉的Camel中的调试日志:
| 62 - org.apache.camel.camel-core - 2.13.2 | Using ComponentResolver: org.apache.camel.impl.DefaultComponentResolver@29668a43 to resolve component with name: sftp
| 62 - org.apache.camel.camel-core - 2.13.2 | Found component: sftp in registry: null
| 62 - org.apache.camel.camel-core - 2.13.2 | Apache Camel 2.13.2 (CamelContext: camel-16) is shutting down
知道骆驼为什么会这样吗?事实上,在独立的应用程序(带有main
方法的Java类)中运行此代码是正确的。
我可以看到:
11:22:13.237 [main] DEBUG o.a.c.impl.DefaultComponentResolver - Found component: sftp in registry: null
11:22:13.239 [main] DEBUG o.a.c.impl.DefaultComponentResolver - Found component: sftp via type: org.apache.camel.component.file.remote.SftpComponent via: META-INF/services/org/apache/camel/component/sftp
但是,在Karaf内部,由于某种原因,只有第一行出现,它找不到
META-INF/services/org/apache/camel/component/sftp
,因此没有找到sftp组件。如果在OSGi内部运行camel,则应该使用camel核心OSGi中的OSGi CamelContext。然后还有几个步骤来为OSGi设置这个
虽然在BlueprintXML文件中使用OSGi blueprint应用程序和引导骆驼通常更容易,但这是正确的
但是对于Java代码来说,它需要一些手动过程。在即将发布的Camel 2.15版本中,有一个新的Camel-scr组件用于处理OSGi和scr(声明性服务),它使使用Camel-scr在OSGi中使用Camel编写java代码变得更加容易
我建议您检查一下它当前的源代码,了解如何从Java代码在OSGi中设置Camel
使用OsgiDefaultCamelContext实际上解决了这个问题,并且不需要将camel ftp捆绑包作为依赖项嵌入(这使得捆绑包更大,而且很难看,因为camel ftp捆绑包已经存在于ServiceMix/Karaf中)。