【问题标题】:Using Apache camel in bundles on Apache karaf在 Apache karaf 上捆绑使用 Apache camel
【发布时间】:2015-12-05 08:41:15
【问题描述】:

我正在尝试将一些文件的内容写入 Apache karaf 的日志文件(仅用于一些测试)。为此,我将以下路线与骆驼一起使用:

from("file:C:/input?noop=true").process(new LogProcessor()).to(
            "stream:out");

LogProcessor 现在什么都不做,我的 pom.xml 看起来像这样(用 maven 构建):

    <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0      http://maven.apache.org/xsd/maven-4.0.0.xsd">

<!--

    Licensed to the Apache Software Foundation (ASF) under one or more
    contributor license agreements.  See the NOTICE file distributed with
    this work for additional information regarding copyright ownership.
    The ASF licenses this file to You under the Apache License, Version 2.0
    (the "License"); you may not use this file except in compliance with
    the License.  You may obtain a copy of the License at

        http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
-->

<modelVersion>4.0.0</modelVersion>

<groupId>osgi</groupId>
<artifactId>osgi</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>bundle</packaging>

<name>osgi Bundle</name>
<description>osgi OSGi bundle project.</description>

<dependencies>
    <dependency>
        <groupId>org.osgi</groupId>
        <artifactId>org.osgi.core</artifactId>
        <version>4.2.0</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-core</artifactId>
        <version>2.14.3</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-simple</artifactId>
        <version>1.7.5</version>
    </dependency>
    <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-stream</artifactId>
        <version>2.14.3</version>
    </dependency>
</dependencies>
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.felix</groupId>
            <artifactId>maven-bundle-plugin</artifactId>
            <version>2.3.7</version>
            <extensions>true</extensions>
            <configuration>
                <instructions>
                    <Bundle-SymbolicName>osgi</Bundle-SymbolicName>
                    <Bundle-Version>1.0-SNAPSHOT</Bundle-Version>
                    <Bundle-Activator>osgi.Activator</Bundle-Activator>
                    <Export-Package>
                        osgi*;version=1.0-SNAPSHOT
                    </Export-Package>
                    <Import-Package>
                        *
                    </Import-Package>
                </instructions>
            </configuration>
        </plugin>
    </plugins>
</build>

我也执行了

features:install camel-stream

在 karaf 上,当然骆驼本身也安装在 karaf 上。

但我还是明白了

[...]No component found with scheme: stream[...]

karaf 错误。

已经浏览了很多论坛和东西,但找不到任何解决方案...感谢任何帮助!

【问题讨论】:

    标签: maven stream apache-camel osgi apache-karaf


    【解决方案1】:

    这有点预感,但我猜你已经在 bundle Activator 中创建了 DefaultCamelContext。然后 Stream Component 不会加载到该上下文中,除非您自己这样做:

    StreamComponent stream = new StreamComponent();
    camelContext.addComponent("stream", stream);
    

    【讨论】:

    • 非常感谢!这就是问题所在,现在它终于起作用了:) - 这是解决这个问题的方法还是有任何其他“最佳实践”解决方案?例如,我在尝试使用 CSV 时遇到了一个类似的问题,但没有 CsvComponent 或类似的东西要添加
    • 如果您自己创建 DefaultCamelContext,那么您必须手动添加组件。如果您愿意使用 Spring,那么它将使用所有可用组件自动为您创建 CamelContext。请参阅camel.apache.org/spring.html 如果您不反对使用 Spring,那么这就是我的建议。请注意,您将不再使用 Bundle Activator,因为 Spring 将激活您的 CamelContext 并向其添加路由。
    • spring 在使用 'mvn:camel run' 的控制台启动时工作正常,但在 Apache karaf 上部署时不起作用
    • 基于 Spring 的包在部署到 Apache Karaf 时应该可以工作,如果没有,那么你有一些配置错误或其他东西。如果您无法弄清楚,我建议您在 Karaf 中打开一个关于 Spring based bundle 的新问题,并给出您所面临的错误。
    • 好的,我做到了。您仍然知道如何让 csv 或 cxf 之类的东西在没有弹簧的情况下工作吗?因为没有要添加的组件,但在 karaf 中仍然存在相同的错误
    猜你喜欢
    • 2014-05-04
    • 2015-05-22
    • 2015-12-04
    • 2012-08-29
    • 2012-04-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-06
    相关资源
    最近更新 更多