Here is the simple spring boot project (version 1.5.2
) to demonstrate the problem:
https://github.com/lanwen/camel-jms-activemq-test
It has Apache Camel version 2.18.3
On branch master
all works fine because of activemq-camel=5.14.4
and camel-jms=2.16.3
(gets transitively from it)
Spring boot application starts normally with log:
2017-04-22 00:53:19.647 INFO 97217 --- [ main] o.a.camel.spring.SpringCamelContext : Apache Camel 2.18.3 (CamelContext: camel-1) is starting
2017-04-22 00:53:19.662 INFO 97173 --- [ main] o.apache.activemq.broker.BrokerService : Apache ActiveMQ 5.14.4 (localhost, ID:lanwen-osx3.local-62145-1492811599544-0:1) is starting
2017-04-22 00:53:19.665 INFO 97173 --- [ main] o.apache.activemq.broker.BrokerService : Apache ActiveMQ 5.14.4 (localhost, ID:lanwen-osx3.local-62145-1492811599544-0:1) started
2017-04-22 00:53:19.665 INFO 97173 --- [ main] o.apache.activemq.broker.BrokerService : For help or more information please see: http://activemq.apache.org
2017-04-22 00:53:19.682 INFO 97173 --- [ main] o.a.activemq.broker.TransportConnector : Connector vm://localhost started
2017-04-22 00:53:19.702 INFO 97173 --- [ main] o.a.camel.spring.SpringCamelContext : Route: route1 started and consuming from: activemq://queue:to-write?asyncConsumer=true
2017-04-22 00:53:19.703 INFO 97173 --- [ main] o.a.camel.spring.SpringCamelContext : Total 1 routes, of which 1 are started.
2017-04-22 00:53:19.704 INFO 97173 --- [ main] o.a.camel.spring.SpringCamelContext : Apache Camel 2.18.3 (CamelContext: camel-1) started in 0.466 seconds
2017-04-22 00:53:19.709 INFO 97173 --- [ main] ru.yandex.test.writer.MyTestApplication : Started MyTestApplication in 2.437 seconds (JVM running for 2.911)
But when you start with camel-jms=2.18.3
(as the main version of camel, on branch not_working)
Things go wrong with this log:
2017-04-22 00:56:38.070 INFO 97195 --- [ main] o.a.camel.spring.SpringCamelContext : Apache Camel 2.18.3 (CamelContext: camel-1) is starting
...
2017-04-22 00:56:43.590 WARN 97195 --- [ActiveMQ Task-1] o.a.a.t.failover.FailoverTransport : Failed to connect to [tcp://localhost:61616] after: 10 attempt(s) continuing to retry.
But if we change activemq-camel
to 5.13.4
with camel-jms=2.18.3
it works fine again...
Why ActiveMQ 5.14.x doesn't work with camel-jms 2.18.x?
The ActiveMQ component allows messages to be sent to a JMS Queue or Topic or messages to be consumed from a JMS Queue or Topic using Apache ActiveMQ.
You use a Queue for point-to-point and Topic for a publish-subscribe model. On a Java platform, JMS - Java Messaging Service provides an interface to a messaging server. Apache activeMQ is one such open source JMS provider. Camel does not ship with a JMS provider; however, it can be configured to use activeMQ.
Apache ActiveMQ® is the most popular open source, multi-protocol, Java-based message broker. It supports industry standard protocols so users get the benefits of client choices across a broad range of languages and platforms. Connect from clients written in JavaScript, C, C++, Python, . Net, and more.
If you add camel-jms-starter to your application’s Maven dependencies, then Camel will configure the JMS component automatically – if it can find a ConnectionFactory. So, in practice, this means that to configure JMS messaging with ActiveMQ Artemis for Camel on Spring Boot, you just need to do 2 things:
Apache Camel makes it pretty easy to send and receive messages from any message broker which supports the JMS API. In this article, I’ll talk about configuring Apache Camel to work with one of the most common message brokers, Apache ActiveMQ. As usual, there’s some example code along the way for you to copy and try out. Which ActiveMQ to use?
The usual way of configuring a component in Camel is: create an instance of the Component object (e.g. JmsComponent jms = new JmsComponent ()) set the component’s properties (e.g. jms.setConnectionFactory ()) add the component to Camel’s bean registry. If you’re using Spring or Spring Boot, then Camel uses your Spring context as a registry.
This ensures that when Camel starts that all the JMS consumers have a valid connection to the JMS broker. If a connection cannot be granted then Camel throws an exception on startup. This ensures that Camel is not started with failed connections. The JMS producers is tested as well.
If you look at the dependency list for the latest Camel ActiveMQ 1.15.5
(https://mvnrepository.com/artifact/org.apache.activemq/activemq-camel/5.14.5), you'll see that it already has camel-jms
as a dependency, but the version is 1.16.3
. So there's no need for you to separately add a camel-jms
1.18.x
dependency in your POM, because it will overwrite the 1.16.x
version that ActiveMQ already uses, which is the compatible one.
So essentially, the issue is that you're trying to use a newer, incompatible version of camel-jms
. When you separately add the 1.18.x
camel-jms
dependency, the ActiveMQ componenet will use this version, which is not compatible with its 1.16.x
version, and hence, the error.
If you need to use ActiveMQ, then you'll probably have to see if camel-jms
1.16.x
will work for you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With