在ActiveMQ中启动时,“Camel正在关闭”

时间:2014-02-01 22:57:53

标签: java spring jpa activemq apache-camel

我目前正在开发一个Java DSL路由,它将从JMS队列中获取消息,对其进行处理,并使用JPA将其放入数据库中。真的很简单:

public void configure() {
        from("{{ribMessage.source}}")
             .split(xpath("/RibMessages/*"))
                .streaming()
                .process(new RibMessageToEntityProcessor())
                .to("{{ribMessage.destination}}");
}

正如您所看到的,我正在尝试使用camel属性,我在类路径的属性文件中定义了这些属性:

ribMessage.source=activemq:queue:in.item_q
ribMessage.destination=jpa:com.axstores.aim.entities.XMLImport

属性文件在spring中定义如下:

<bean id="properties" class="org.apache.camel.component.properties.PropertiesComponent">
    <property name="location" value="classpath:ribmessage.properties"/>
</bean>

我已经更新了activemq配置以包含camel.xml,并且我已经将我的路由包添加到ActiveMQ camel.xml中。在启动期间,ActiveMQ正在找到我的路由,但后来看起来它无法找到我的属性,而是查找URI {{ribMessage.source}}。这当然失败了,日志中的下一行说Camel正在关闭。

2014-02-01 23:31:20,278 | DEBUG | Searching for implementations of org.apache.camel.RoutesBuilder in packages: [com.axstores.aim] | org.apache.camel.impl.DefaultPackageScanClassResolver | main
2014-02-01 23:31:20,374 | DEBUG | Found: [class com.axstores.aim.routes.RibMessageToAimRoute] | org.apache.camel.impl.DefaultPackageScanClassResolver | main
...
2014-02-01 23:46:52,410 | TRACE | Starting service | org.apache.camel.support.ServiceSupport | main
2014-02-01 23:46:52,414 | TRACE | Getting endpoint with uri: {{ribMessage.source}} | org.apache.camel.spring.SpringCamelContext | main
2014-02-01 23:46:52,416 | INFO  | Apache Camel 2.12.1 (CamelContext: camel) is shutting down | org.apache.camel.spring.SpringCamelContext | main

我怀疑我的配置中缺少一些东西,因为在我看来,我的弹簧配置文件根本就没有读过。

任何线索?需要更多信息?

Full log for reference

Spring config

2 个答案:

答案 0 :(得分:3)

您需要将camel-jpa组件JAR添加到ActiveMQ代理的类路径中。以及JPA可能需要的其他JAR,例如JPA实现和JDBC驱动程序等等。

答案 1 :(得分:0)

因此,在克劳斯和彼得的帮助下,以及一些反复试验的帮助下,我终于能够通过我的路线开始运行ActiveMQ。

我的配置中遗漏了一件大事,基本上搞砸了其他一切。 Active MQ能够通过配置找到我的路由,但它似乎仍然没有加载我的spring配置。 我终于想通了,我必须将以下import语句添加到我的ActiveMQ camel.xml中,以便从我的jar文件中加载spring配置。

<import resource="classpath:META-INF/spring/camel-context.xml"/>

添加这个允许ActiveMQ来解析我的ribmessage.properties,正如彼得在上面的评论中所提到的,这最初根本没有完成。这也加载了我的JPA配置,它揭示了一堆丢失的罐子,正如克劳斯在上面的评论中指出的那样。

对于这个项目我正在使用EclipseLink和Oracle 11g,所以除了camel-jpa之外,我还必须将以下jar添加到ActiveMQ类路径中:

ojdbc7-12.1.0.1.jar
eclipselink-2.5.1.jar
spring-orm-3.2.4.RELEASE.jar
persistence-api-1.0.jar
spring-jdbc-3.2.4.RELEASE.jar

希望有人可以从我的经验中受益。 我一个星期前才真正发现了Camel,它似乎是构建集成的一个很棒的框架: - )

相关问题