无法在Karaf 4.1.0或ServiceMix 7.0.0(Karaf 4.0.8)

时间:2017-03-08 22:49:18

标签: apache-camel cdi karaf pax

我一直试图用Camel和CDI构建和部署一个简单的路由,但没有成功。我专注于部署到ServiceMix 7.0.0,但也在jane Karaf 4.1.0平面上尝试了这一点并得到了完全相同的结果。

我根据2.16.4和2.18.2中的Camel CDI示例构建了一个非常简单的路由。我暂时排除了一些测试内容,只是在我在Karaf / ServiceMix中部署它时试图让它工作。

我的RouteBuilder是:

public class DemoRouteBuilder extends RouteBuilder {
    Logger log = LoggerFactory.getLogger(DemoRouteBuilder.class);

    @Override
    public void configure() {
        log.info("Starting demo CDI route");
        from("timer://cdiTimer?period=5000")
          .routeId("com.omniprise.demo.cdi.route")
          .to("log:com.omniprise..demo.cdi.context")
          .to("mock:end");
    }
}

我的POM中也有必要的内容:

            <Export-Package>com.omniprise.demo.cdi.builder</Export-Package>
            <Import-Package>*</Import-Package>
            <Require-Capability>
              osgi.extender; filter:="(osgi.extender=pax.cdi)",
              org.ops4j.pax.cdi.extension; filter:="(extension=camel-cdi-extension)"
            </Require-Capability>

完整的Java和POM代码就在问题的最后。

请注意,由于依赖性冲突,camel-cdi功能将无法在ServiceMix 7.0.0上安装:

  • ServiceMix 7.0.0正在使用Camel 2.16.4
  • 2.16.4中的
  • camel-cdi正在寻找DeltaSpike [1.5.0,2.0]
  • 2.16.4中的camel-cdi正在寻找pax-cdi 1.0.0.RC1
  • pax-cdi安装DeltaSpike 1.3.1
  • ...因此,如果完成所有操作,则会发生未解决的依赖性错误:

    feature:install pax-cdi pax-cdi-weld camel-cdi
    

新版本的Camel也存在类似的问题。

另请注意,即使包含更新的DeltaSpike库,pax-cdi 1.0.0.RC1也会出现错误,可能是由于Blueprint代理存在问题。

因此,这些说明安装了pax-cdi 1.0.0.RC2和最新的DeltaSpike 1.7.2以及camel-cdi(ServiceMix 7.0.0为2.16.4,Karaf 4.1.0为2.18.2)。 / p>

在ServiceMix 7.0.0中安装和运行(Karaf 4.0.8,Camel 2.16.4)

启动ServiceMix,连接到Karaf控制台并安装:

feature:repo-add mvn:org.ops4j.pax.cdi/pax-cdi-features/1.0.0.RC2/xml/features
install mvn:org.apache.deltaspike.core/deltaspike-core-api/1.7.2
install mvn:org.apache.deltaspike.core/deltaspike-core-impl/1.7.2
feature:install pax-cdi/1.0.0.RC2
feature:install pax-cdi-weld/1.0.0.RC2
feature:install camel-cdi
install -s mvn:com.omniprise.demo/camel-osgi-cdi/0.0.1-SNAPSHOT

在普通jane Karaf 4.x环境中安装和运行(Camel 2.18.2)

启动Karaf,连接到Karaf控制台并安装:

feature:repo-add mvn:org.apache.camel.karaf/apache-camel/2.18.2/xml/features
feature:repo-add mvn:org.ops4j.pax.cdi/pax-cdi-features/1.0.0.RC2/xml/features
install mvn:org.apache.deltaspike.core/deltaspike-core-api/1.7.2
install mvn:org.apache.deltaspike.core/deltaspike-core-impl/1.7.2
feature:install pax-cdi/1.0.0.RC2
feature:install pax-cdi-weld/1.0.0.RC2
feature:install camel/2.18.2
feature:install camel-blueprint/2.18.2
feature:install camel-cdi/2.18.2
install -s mvn:com.omniprise.demo/camel-osgi-cdi/0.0.1-SNAPSHOT

在这两种情况下,软件包都已安装并列为正在运行,但Camel Context尚未启动:

70 | Active    |  80 | 1.0.0.RC2      | OPS4J Pax CDI Bean Bundle API
71 | Active    |  80 | 1.0.0.RC2      | OPS4J Pax CDI Extender for Bean Bundles
72 | Active    |  80 | 1.0.0.RC2      | OPS4J Pax CDI Portable Extension for OSGi
73 | Active    |  80 | 1.0.0.RC2      | OPS4J Pax CDI Service Provider Interface
74 | Active    |  80 | 1.0.0.RC2      | OPS4J Pax CDI Weld Adapter
... content removed for brevity
83 | Active    |  50 | 2.18.2         | camel-cdi
... content removed for brevity
92 | Active    |  80 | 1.8.1          | OPS4J Pax Swissbox :: Tracker
93 | Active    |  80 | 0.0.1.SNAPSHOT | Camel CDI OSGi Demo
addmin@root()> camel:context-list
addmin@root()>

与camel-cdi安装pax-cdi 1.0.0.RC1相关联的日志中只有一个错误,即使pax-cdi 1.0.0.RC2已经存在,因此CDI提供程序已经注册。在日志结束时,很明显CDI绑定正在启动,但没有创建Context,并且Route不会产生消息 - 没有任何迹象表明找到RouteBuilder有问题或者开始:

2017-03-08T15:50:24,568 | INFO  | pipe-feature:install camel-blueprint/2.18.2 | CdiExtender                      | 71 - org.ops4j.pax.cdi.extender - 1.0.0.RC2 | creating CDI container for bean bundle camel-osgi-cdi [93] with extension bundles [org.apache.camel.camel-cdi [83]]
2017-03-08T15:50:24,575 | INFO  | pipe-feature:install camel-blueprint/2.18.2 | AbstractCdiContainer             | 73 - org.ops4j.pax.cdi.spi - 1.0.0.RC2 | Starting CDI container for bundle camel-osgi-cdi [93]
2017-03-08T15:50:24,598 | INFO  | pipe-feature:install camel-blueprint/2.18.2 | Version                          | 69 - org.jboss.weld.osgi-bundle - 2.3.5.Final | WELD-000900: 2.3.5 (Final)
2017-03-08T15:50:24,745 | INFO  | pipe-feature:install camel-blueprint/2.18.2 | Bootstrap                        | 69 - org.jboss.weld.osgi-bundle - 2.3.5.Final | WELD-000101: Transactional services not available. Injection of @Inject UserTransaction not available. Transactional observers will be invoked synchronously.
2017-03-08T15:50:24,810 | WARN  | pipe-feature:install camel-blueprint/2.18.2 | Interceptor                      | 69 - org.jboss.weld.osgi-bundle - 2.3.5.Final | WELD-001700: Interceptor annotation class javax.ejb.PostActivate not found, interception based on it is not enabled
2017-03-08T15:50:24,811 | WARN  | pipe-feature:install camel-blueprint/2.18.2 | Interceptor                      | 69 - org.jboss.weld.osgi-bundle - 2.3.5.Final | WELD-001700: Interceptor annotation class javax.ejb.PrePassivate not found, interception based on it is not enabled
2017-03-08T15:50:24,938 | INFO  | pipe-feature:install camel-blueprint/2.18.2 | Event                            | 69 - org.jboss.weld.osgi-bundle - 2.3.5.Final | WELD-000411: Observer method [BackedAnnotatedMethod] private org.apache.camel.cdi.CdiCamelExtension.processAnnotatedType(@Observes ProcessAnnotatedType<?>) receives events for all annotated types. Consider restricting events using @WithAnnotations or a generic type with bounds.

源代码

在我非常简单的POM和Class项目中,有两个文件。 pom.xml位于项目根文件夹中:

<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">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.omniprise.demo</groupId>
  <artifactId>camel-osgi-cdi</artifactId>
  <version>0.0.1-SNAPSHOT</version>

  <name>Camel CDI OSGi Demo</name>
  <description>Deploys simple routes using Camel Java DSL in ServiceMix OSGi Karaf container using CDI</description>

  <packaging>bundle</packaging>

  <properties>
    <default.encoding>UTF-8</default.encoding>
    <project.build.sourceEncoding>${default.encoding}</project.build.sourceEncoding>
    <project.reporting.outputEncoding>${default.encoding}</project.reporting.outputEncoding>
    <java.version>1.8</java.version>
    <slf4j.version-range>[1.7.2,1.8)</slf4j.version-range>
    <log4j.version>1.2.17</log4j.version>
    <!-- Maven Plugins -->
    <maven-bundle-plugin.version>3.2.0</maven-bundle-plugin.version>
    <maven-bundle-plugin.version>3.2.0</maven-bundle-plugin.version>
    <maven-compiler-plugin.version>3.6.0</maven-compiler-plugin.version>
    <maven-resources-plugin.version>3.0.2</maven-resources-plugin.version>
    <maven-resources-plugin.encoding>${default.encoding}</maven-resources-plugin.encoding>
    <depends-maven-plugin.version>1.3.1</depends-maven-plugin.version>
    <!-- Tools -->
    <!-- camel.version>2.16.4</camel.version -->
    <camel.version>2.18.2</camel.version>
    <!-- camel-cdi.version>2.16.4</camel-cdi.version -->
    <camel-cdi.version>2.18.2</camel-cdi.version>
    <cdi-api.version>1.2</cdi-api.version>
  </properties>

  <dependencies>
    <dependency>
      <groupId>javax.enterprise</groupId>
      <artifactId>cdi-api</artifactId>
      <version>${cdi-api.version}</version>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>org.apache.camel</groupId>
      <artifactId>camel-core</artifactId>
      <version>${camel.version}</version>
    </dependency>
    <dependency>
      <groupId>org.apache.camel</groupId>
      <artifactId>camel-blueprint</artifactId>
      <version>${camel.version}</version>
    </dependency>
    <dependency>
      <groupId>org.apache.camel</groupId>
      <artifactId>camel-cdi</artifactId>
      <version>${camel-cdi.version}</version>
    </dependency>
    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-api</artifactId>
      <version>${slf4j.version-range}</version>
    </dependency>
    <!-- Testing -->
    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-log4j12</artifactId>
      <version>${slf4j.version-range}</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>log4j</groupId>
      <artifactId>log4j</artifactId>
      <version>${log4j.version}</version>
      <scope>test</scope>
    </dependency>
  </dependencies>

  <build>
    <defaultGoal>install</defaultGoal>
    <finalName>${project.artifactId}</finalName>

    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>${maven-compiler-plugin.version}</version>
        <configuration>
          <source>${java.version}</source>
          <target>${java.version}</target>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-resources-plugin</artifactId>
        <version>${maven-resources-plugin.version}</version>
        <configuration>
          <encoding>${maven-resources-plugin.encoding}</encoding>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.apache.servicemix.tooling</groupId>
        <artifactId>depends-maven-plugin</artifactId>
        <version>${depends-maven-plugin.version}</version>
        <executions>
          <execution>
            <id>generate-depends-file</id>
            <goals>
              <goal>generate-depends-file</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.apache.felix</groupId>
        <artifactId>maven-bundle-plugin</artifactId>
        <version>${maven-bundle-plugin.version}</version>
        <extensions>true</extensions>
        <configuration>
          <remoteOBR />
          <instructions>
            <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
            <Private-Package></Private-Package>
            <Export-Package>com.omniprise.demo.cdi.builder</Export-Package>
            <Import-Package>*</Import-Package>
            <Require-Capability>
              osgi.extender; filter:="(osgi.extender=pax.cdi)",
              org.ops4j.pax.cdi.extension; filter:="(extension=camel-cdi-extension)"
            </Require-Capability>
          </instructions>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

DemoRouteBuilder.java位于src / main / java / com / omniprise / demo / cdi / builder

package com.omniprise.demo.cdi.builder;

import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.cdi.ContextName;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

//@ContextName("com.omniprise.demo.cdi.context")
public class DemoRouteBuilder extends RouteBuilder {
    Logger log = LoggerFactory.getLogger(DemoRouteBuilder.class);

    @Override
    public void configure() {
        log.info("Starting demo CDI route");
        from("timer://cdiTimer?period=5000")
          .routeId("com.omniprise.demo.cdi.route")
          .to("log:com.omniprise.demo.cdi.context")
          .to("mock:end");
    }
}

我无法弄清楚为什么DemoRouteBuilder类没有被CDI基础设施调用,而CDI基础设施应该找到所有的RouteBuilder实例并触发它们。

0 个答案:

没有答案