Helidon Messaging with JMS

Daniel Kec
Helidon
Published in
3 min readFeb 23, 2021

Reactive messaging with JMS connector

When it comes to integration with messaging systems, JMS API is one of the most popular solutions out there. So it’s no wonder Helidon 2.2.0 comes with direct support for connecting its reactive messaging to JMS.

Let’s try to connect Helidon to Apache ActiveMQ over JMS, it’s super easy to set up and we can focus on the connector itself.

First, start ActiveMQ in the docker:

docker run --name='activemq' -p 61616:61616 -p 8161:8161 rmohr/activemq

When we have JMS server to play with, it’s time for tweaking Helidon.

JMS Messaging with Helidon MP

To connect Helidon MP, we are going to need MicroProfile Reactive Messaging implementation, Helidon’s JMS messaging connector, and the ActiveMQ client library.

Dependencies needed for connecting ActiveMQ over JMS

Injecting ConnectionFactory

The easiest way to prepare JMS connection is to manually create the ConnectionFactory as a named, application-scoped bean.

Creating connection factory as named bean

The named bean can be referenced by JMS connector config with named-factory property.

Referencing connection factory injected as bean

Once configured, you can consume and publish some messages:

Consume:

Publish:

Configuration with JNDI

Looking up ConnectionFactory with JNDI makes it possible to set up JMS connection with configuration only. All you need to configure JNDI is the name of the connection factory with jndi.jms-factory key, and properties of the initial factory to env-properties — like java.naming.factory.initial and java.naming.provider.url.

Configuration with JNDI

The result is the same as when you inject your own connection factory as a bean. For more information about this solution, try the example project in the Helidon repository.

JMS Messaging with Helidon SE

Helidon SE Messaging is a dependency of JMS connector, so all you need is dependency for the connector itself and for the sake of our example ActiveMQ client containing implementation of JMS ConnectionFactory.

Dependencies needed for connecting ActiveMQ with Helidon SE

There are basically two ways of managing connection factory in the Helidon SE environment: supplying your own connection factories or using JNDI.

Custom ConnectionFactory

Supplying your own connection factory is the most versatile approach you can take. As it is possible to use multiple connection factories in one connector, you have to provide custom identifiers for referencing it from channel configurations.

Complete example of sending and receiving JMS messages

It’s all there in one snippet, Abracadabra!✨ no-magic it is!

As you can see, the whole example is self contained, you don’t need any other part of Helidon to run it as there is no hidden magic involved. Actually, if you just place this example to main method, it will work as is.

Configuration with JNDI

We can also look up connection factory over a JNDI.

Looking up connection factory with JNDI

This doesn’t look much more practical until you supply configuration directly. Let’s just take yaml config with JNDI lookup from the MP example above. We will need one more dependency to allow config to understand yaml.

<dependency>
<groupId>io.helidon.config</groupId>
<artifactId>helidon-config-yaml</artifactId>
</dependency>

You can see that the config is exactly the same like the one used in MP example.

Same config as in the MP example above

Now let's use it with SE messaging. This is no problem at all because JMS connector understands MP messaging config notation in both flavors.

SE JMS connector with MP messaging config notation

For more information about JMS connector in Helidon SE, try the example project in the Helidon repository.

JMS connector in Helidon opens new doors for integrating to other services with reactive messaging. Among these services, Weblogic JMS and Oracle AQ are quite interesting. We will focus more on those in the following articles.

Happy messaging!

For more info about Reactive Messaging in Helidon:

--

--