1
votes

I'm currently developing a Java DSL route, which will fetch a message from a JMS queue, process it, and put it in a database using JPA. Fairly simple really:

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

As you can see, I'm trying to use camel properties here, which I have defined in a properties file on my classpath:

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

The properties file is defined in spring like so:

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

I've updated the activemq config to include a camel.xml, and I've added my route package to the ActiveMQ camel.xml. And during startup, ActiveMQ is finding my route, but then it looks like it isn't able to find my property, and looks up URI {{ribMessage.source}} instead. This fails of course, and the next line in the log says that Camel is shutting down.

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

I suspect that I'm missing something in my config, because it seems to me like my spring config file is not being read at all.

Any clues? More info needed?

Full log for reference

Spring config

2
In the log file I see no hint that the ribmessage.properties is read. How do you start the routes? Could you provide your main class?Peter Keller
It might be that this is where the error is. I don't have a main class, as my understanding was that my route is supposed to be "injected" into the camel context that is started by Active MQ. My thinking is that having a main class would be redundant, as that would start another camel context, parallell to the one started by Active MQ. Did I misunderstand this?Daniel

2 Answers

3
votes

You need to add the camel-jpa component JAR to the classpath of the ActiveMQ broker. And as well what additional JARs you may need for JPA such as the JPA implementation and JDBC drivers and whatnot.

0
votes

So with some help from the Claus and Peter gave, and some trial and error, I was finally able to get going ActiveMQ up and running, with my routes.

There was one major thing I missed in my config, which basically screwed up everything else. Active MQ was able to find my route through the config, but it still didn't seem to load my spring config. I finally figured out that I had to add the following import statement to my ActiveMQ camel.xml, in order for it to load the spring config from my jar file.

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

Adding this allowed ActiveMQ to resolve my ribmessage.properties, as Peter mentioned in a comment above, this was not being done at all initially. This also loaded my JPA config, which revealed a bunch of missing jars, as Claus pointed out in the comment above.

For this project I'm using EclipseLink and Oracle 11g, so besides camel-jpa, I also had to add the follwing jars to the ActiveMQ classpath:

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

Hopefully someone can benefit from my (in)experiences. I really only discovered Camel one week ago, and it seems to be an awesome framework for building integrations :-)