骆驼找不到“sftp"注册表中的组件并关闭 [英] Camel not finding "sftp" component in registry and shutting down

查看:30
本文介绍了骆驼找不到“sftp"注册表中的组件并关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用camel-sftp 组件将文件上传到SFTP 服务器.代码很简单:

I'm using the camel-sftp component to upload a file to an SFTP server. The code is simple:

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 中激活调试日志,它会抱怨:

However, camel has problems finding the sftp component. Activating the debug logs in Camel it complains:

| 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 类)中运行此代码可以正常工作.我可以看到:

Any ideas why Camel is behaving this way? In fact, running this code in a standalone application (a Java class with a main method) works correctly. And I can see:

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 组件.

Inside of Karaf, though, only the first line appears, for some reason or other it does not find META-INF/services/org/apache/camel/component/sftp and as a result the sftp component is not found.

推荐答案

如果你在 OSGi 中运行 Camel,你应该使用来自 camel-core-osgi 的 OSGi CamelContext.然后还有一些步骤可以为 OSGi 设置它.

If you run Camel inside OSGi, you should use the OSGi CamelContext from camel-core-osgi. And then there is a few more steps to setup this for OSGi.

尽管在蓝图 xml 文件中使用 OSGi 蓝图应用程序和引导 Camel 通常更容易,但这样做是正确的.

Though its often easier to use a OSGi blueprint application and bootstrap Camel in the blueprint xml file, which does this correctly.

但是对于 Java 代码,它需要一些手动过程.在即将发布的 Camel 2.15 版本中,有一个新的 camel-scr 组件用于处理 OSGi 和 SCR(声明性服务),这使得使用 camel-scr 在 OSGi 中使用 Camel 执行 Java 代码变得更加容易.

But for Java code its some manual process. In the upcoming Camel 2.15 release there is a new camel-scr component for working with OSGi and SCR (Declarative Services) which makes it easier to do java code with Camel in OSGi using camel-scr.

我建议检查其当前的源代码以获得灵感,如何从 Java 代码在 OSGi 中设置 Camel

I would suggest to check its current source code for inspiration how you can setup Camel in OSGi from Java code

https://github.com/apache/camel/tree/master/components/camel-scr

这篇关于骆驼找不到“sftp"注册表中的组件并关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆