【问题标题】:Camel ActiveMq BlueprintCamel ActiveMq 蓝图
【发布时间】:2016-06-29 18:01:57
【问题描述】:

我是骆驼和蓝图的新手。

我正在尝试制作一个简单的程序来将数据放入队列中。 不知道这里出了什么问题。

骆驼上下文文件 ==>

<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:camel="http://camel.apache.org/schema/blueprint"
    xsi:schemaLocation="
       http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
       http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint.xsd">

    <bean id="helloBean" class="com.camelSampleBundle.HelloBean">
        <property name="say" value="Hi from Camel" />
    </bean>
    <bean id="activemq" class="org.apache.activemq.camel.component.ActiveMQComponent">
        <property name="brokerURL" value="tcp://localhost:61616" />
    </bean>
    <camelContext id="blueprintContext" trace="false"
        xmlns="http://camel.apache.org/schema/blueprint">
        <route id="timerToLog">
            <from uri="timer:foo?period=5000" />
            <setBody>
                <constant>Hello World!</constant>
            </setBody>
            <to uri="activemq:camel.q.timer" />
            <log message="The message contains ${body}" />

        </route>
        <!-- <route id="anotherRoute">
            <from uri="activemq:camel.q.timer" />
            <log message="The message contains ${body}" />
            <to uri="mock:result" />
        </route> -->
    </camelContext>

</blueprint>

POM.xml

<?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/maven-v4_0_0.xsd">

    <modelVersion>4.0.0</modelVersion>

    <groupId>com.camelSampleBundle</groupId>
    <artifactId>camel-sampleBundle</artifactId>
    <packaging>bundle</packaging>
    <version>1.0.0-SNAPSHOT</version>

    <name>Sample Bundle</name>
    <url>http://www.myorganization.org</url>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <fuse.version>2.12.0.redhat-610379</fuse.version>
    </properties>

    <repositories>
        <repository>
            <id>release.fusesource.org</id>
            <name>FuseSource Release Repository</name>
            <url>http://repo.fusesource.com/nexus/content/repositories/releases</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
            <releases>
                <enabled>true</enabled>
            </releases>
        </repository>
        <repository>
            <id>snapshot.fusesource.org</id>
            <name>FuseSource Snapshot Repository</name>
            <url>http://repo.fusesource.com/nexus/content/repositories/snapshots</url>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
            <releases>
                <enabled>false</enabled>
            </releases>
        </repository>
    </repositories>

    <pluginRepositories>
        <pluginRepository>
            <id>release.fusesource.org</id>
            <name>FuseSource Release Repository</name>
            <url>http://repo.fusesource.com/nexus/content/repositories/releases</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
            <releases>
                <enabled>true</enabled>
            </releases>
        </pluginRepository>
        <pluginRepository>
            <id>snapshot.fusesource.org</id>
            <name>FuseSource Snapshot Repository</name>
            <url>http://repo.fusesource.com/nexus/content/repositories/snapshots</url>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
            <releases>
                <enabled>false</enabled>
            </releases>
        </pluginRepository>
    </pluginRepositories>

    <dependencies>
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-core</artifactId>
            <version>2.10.0.redhat-60024</version>
        </dependency>
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-blueprint</artifactId>
            <version>2.10.0.redhat-60024</version>
        </dependency>
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-jms</artifactId>
            <version>2.10.0.redhat-60024</version>
        </dependency>
        <dependency>
            <groupId>org.apache.activemq</groupId>
            <artifactId>activemq-camel</artifactId>
            <version>5.13.2</version>
        </dependency>



        <!-- logging -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.6.6</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>1.6.6</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>jcl-over-slf4j</artifactId>
            <version>1.6.6</version>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
        </dependency>

        <!-- testing -->
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-test-blueprint</artifactId>
            <version>2.10.0.redhat-60024</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <defaultGoal>install</defaultGoal>

        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.5.1</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <version>2.4.3</version>
                <configuration>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>

            <!-- to generate the MANIFEST-FILE of the bundle -->
            <plugin>
                <groupId>org.apache.felix</groupId>
                <artifactId>maven-bundle-plugin</artifactId>
                <version>2.3.7</version>
                <extensions>true</extensions>
                <configuration>
                    <instructions>
                        <Bundle-SymbolicName>camel-sampleBundle</Bundle-SymbolicName>
                        <Import-Package>*</Import-Package>
                        <Export-Package />
                    </instructions>
                </configuration>
            </plugin>

            <!-- to run the example using mvn camel:run -->
            <plugin>
                <groupId>org.apache.camel</groupId>
                <artifactId>camel-maven-plugin</artifactId>
                <version>2.10.0.redhat-60024</version>
                <configuration>
                    <useBlueprint>true</useBlueprint>
                </configuration>
            </plugin>

        </plugins>
    </build>

</project>

错误堆栈跟踪 ==>

org.osgi.service.blueprint.container.ComponentDefinitionException: 无法实例化组件 org.apache.aries.blueprint.container.BlueprintContainerImpl.instantiateEagerComponents(BlueprintContainerImpl.java:671) 在 org.apache.aries.blueprint.container.BlueprintContainerImpl.doRun(BlueprintContainerImpl.java:370) 在 org.apache.aries.blueprint.container.BlueprintContainerImpl.run(BlueprintContainerImpl.java:261) 在 java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471) 在 java.util.concurrent.FutureTask.run(FutureTask.java:262) 在 org.apache.aries.blueprint.container.ExecutorServiceWrapper.run(ExecutorServiceWrapper.java:106) 在 org.apache.aries.blueprint.utils.threading.impl.DiscardableRunnable.run(DiscardableRunnable.java:48) 在 java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471) 在 java.util.concurrent.FutureTask.run(FutureTask.java:262) 在 java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:178) 在 java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:292) 在 java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) 在 java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) 在 java.lang.Thread.run(Thread.java:745) 引起: java.lang.NoClassDefFoundError: org/apache/camel/spi/EndpointCompleter 在 java.lang.ClassLoader.defineClass1(Native Method) 在 java.lang.ClassLoader.defineClass(ClassLoader.java:800) 在 java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142) 在 java.net.URLClassLoader.defineClass(URLClassLoader.java:449) 在 java.net.URLClassLoader.access$100(URLClassLoader.java:71) 在 java.net.URLClassLoader$1.run(URLClassLoader.java:361) 在 java.net.URLClassLoader$1.run(URLClassLoader.java:355) 在 java.security.AccessController.doPrivileged(Native Method) 在 java.net.URLClassLoader.findClass(URLClassLoader.java:354) 在 java.lang.ClassLoader.loadClass(ClassLoader.java:425) 在 sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) 在 java.lang.ClassLoader.loadClass(ClassLoader.java:358) 在 de.kalpatec.pojosr.framework.PojoSRBundle.loadClass(PojoSRBundle.java:431) 在 org.apache.aries.blueprint.container.BlueprintContainerImpl.loadClass(BlueprintContainerImpl.java:419) 在 org.apache.aries.blueprint.container.BlueprintRepository.loadClass(BlueprintRepository.java:410) 在 org.apache.aries.blueprint.container.GenericType.parse(GenericType.java:113) 在 org.apache.aries.blueprint.di.AbstractRecipe.doLoadType(AbstractRecipe.java:168) 在 org.apache.aries.blueprint.di.AbstractRecipe.loadType(AbstractRecipe.java:161) 在 org.apache.aries.blueprint.container.BeanRecipe.loadClass(BeanRecipe.java:249) 在 org.apache.aries.blueprint.container.BeanRecipe.getType(BeanRecipe.java:895) 在 org.apache.aries.blueprint.container.BeanRecipe.getInstance(BeanRecipe.java:323) 在 org.apache.aries.blueprint.container.BeanRecipe.internalCreate2(BeanRecipe.java:806) 在 org.apache.aries.blueprint.container.BeanRecipe.internalCreate(BeanRecipe.java:787) 在 org.apache.aries.blueprint.di.AbstractRecipe$1.call(AbstractRecipe.java:79) 在 java.util.concurrent.FutureTask.run(FutureTask.java:262) 在 org.apache.aries.blueprint.di.AbstractRecipe.create(AbstractRecipe.java:88) 在 org.apache.aries.blueprint.container.BlueprintRepository.createInstances(BlueprintRepository.java:245) 在 org.apache.aries.blueprint.container.BlueprintRepository.createAll(BlueprintRepository.java:183) 在 org.apache.aries.blueprint.container.BlueprintContainerImpl.instantiateEagerComponents(BlueprintContainerImpl.java:667) ... 13 更多原因:java.lang.ClassNotFoundException: org.apache.camel.spi.EndpointCompleter 在 java.net.URLClassLoader$1.run(URLClassLoader.java:366) 在 java.net.URLClassLoader$1.run(URLClassLoader.java:355) 在 java.security.AccessController.doPrivileged(Native Method) 在 java.net.URLClassLoader.findClass(URLClassLoader.java:354) 在 java.lang.ClassLoader.loadClass(ClassLoader.java:425) 在 sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) 在 java.lang.ClassLoader.loadClass(ClassLoader.java:358) ... 42 更多

【问题讨论】:

    标签: java apache-camel osgi blueprint-osgi


    【解决方案1】:

    你的 OSGI 环境中是否安装了 camel-core ?如果您使用的是 karaf (2.x.x),请输入

    功能:列表 | grep 骆驼

    如果没有显示,你可以做一个:

    特点:选择url骆驼

    添加存储库,然后:

    特点:安装骆驼核心

    我强烈建议您阅读“OSGi 实战”。 ClassNotFoundException 通常表明您的上下文对另一个包将导出的类没有可见性。由于“org/apache/camel/spi/EndpointCompleter”是camel-core,你必须在你的osgi环境中安装它。

    检查包是否被导出:

    jschoreels@lab> exports | grep camel.spi
       100 org.apache.camel.spi; version="2.14.3"  
    jschoreels@lab> list | grep 100
    START LEVEL 100 , List Threshold: 50
    [ 100] [Active     ] [            ] [       ] [   50] camel-core (2.14.3)
    

    但是,您的捆绑包也必须导入此包。你可以做一个:

    imports <bundleidOfYourImportingBundle>
    

    并检查包裹是否在那里。

    如果没有,您必须检查您是否正确构建了捆绑包。一个正确的包应该在 MANIFEST.MF 中声明一些 OSGi 标头。 You can have an example here.

    要使用 maven 生成它,您应该考虑使用依赖 bnd 的 maven bundle plugin

    这是一个使用它的例子:

    <build>
         <plugins>
                <plugin>
                    <groupId>org.apache.felix</groupId>
                    <artifactId>maven-bundle-plugin</artifactId>
                    <version>${maven-bundle-pulgin.version}</version>
                    <configuration>
                        <instructions>
                            <Import-Package>*</Import-Package>
                            <Export-Package />
                        </instructions>
                    </configuration>
                </plugin>
        </plugins
    </build>
    

    如果你想学习 OSGi,我真的推荐你 OSGi in action 并至少阅读三层(模块化、生命周期和服务)章节来了解发现是如何工作的。最后解释了什么是 bnd 以及如何使用它。

    【讨论】:

    • 我的 karaf 中安装了骆驼。
    • 你能检查一下 org.apache.camel.spi 是否被它导出?查看我的答案,最后一个代码 sn-p,以了解如何检查。
    • 感谢乔纳森的回复。我使用的方法是使用 maven 编译程序,然后在 Karaf 上安装生成的 .jar 文件。我得到的这个错误是使用 Maven 安装。还有其他方法吗?
    • 那么您遇到的问题很简单:OSGi 依靠清单来知道要为包导入什么。在您的 Karaf 中,执行“imports ”以查看您的捆绑包是否导入。如果它是一个标准的 .jar,我不知道 karaf 是否有一个规则来导入所有需要的包。如果不是(可能是这种情况),您应该考虑使用依赖 bnd 的 bundle 插件来生成导入包。检查这个:felix.apache.org/documentation/subprojects/… 我会在我的回答中放另一个 sn-p 示例。
    • 感谢您的精心描述。我添加了费利克斯。还是同样的问题。已经粘贴了我的 pom.xml
    【解决方案2】:

    堆栈跟踪提示您似乎在模拟 OSGi 环境中运行骆驼上下文。

    de.kalpatec.pojosr.framework.PojoSRBundle.loadClass(PojoSRBundle.java:431)
    

    尝试在 karaf 等真实的 OSGi 环境中运行它。

    【讨论】:

    • 嗨,克里斯蒂安,感谢您的回复。要在 karaf 中运行它,我首先使用 maven 编译它,然后将其安装在 karaf 上,还有其他方法吗?
    • 我使用的方法是使用maven编译程序,然后在Karaf上安装生成的.jar文件。我得到的这个错误是使用 Maven 安装。还有其他方法吗?
    • 该方法还可以,但是您似乎在构建中进行了集成测试失败。您可以尝试忽略此测试。
    【解决方案3】:

    问题出在骆驼的版本上。 我在 pom.xml 中更改了骆驼版本,效果很好

    <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-core</artifactId>
            <version>2.12.0.redhat-610379</version>
        </dependency>
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-blueprint</artifactId>
            <version>2.12.0.redhat-610379</version>
        </dependency>
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-jms</artifactId>
            <version>2.12.0.redhat-610379</version>
        </dependency>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-12-17
      • 1970-01-01
      • 2015-10-03
      • 2013-01-02
      • 1970-01-01
      • 2018-01-31
      • 1970-01-01
      • 2022-01-19
      相关资源
      最近更新 更多