OpenLiberty / open-liberty

Open Liberty is a highly composable, fast to start, dynamic application server runtime environment
https://openliberty.io
Eclipse Public License 2.0
1.15k stars 592 forks source link

Add Jakarta Messaging (JMS) documentation and example #28230

Open inad9300 opened 6 months ago

inad9300 commented 6 months ago

I'm looking into using ActiveMQ Artemis in my Open Liberty project in an idiomatic way. I was not able to find any good materials that explained how to specify a Jakarta Messaging provider for Open Liberty to use.

Is there any documentation and/or examples on how to use a third-party JMS implementation? If not, it would be great to have them, ideally for the latest version of ActiveMQ (Artemis).

I've come across a few efforts initiated in the past to add support and/or document how to integrate ActiveMQ into Open Liberty, but I was not able to find the fruits of this work:

NottyCode commented 6 months ago

Liberty JMS makes use of Java Connector Architecture (or Jakarta Connectors for the newer standards). ActiveMQ Artemis provides two different resource adapters depending on whether you are using Java EE 8 or Jakarta EE 9 (I assume the Jakarta EE 9 will work on 10, but I'm not an ActiveMQ Artemis expert). These are available in maven central using the following coordinates:

For JMS 2

<dependency>
    <groupId>org.apache.activemq</groupId>
    <artifactId>artemis-jakarta-ra</artifactId>
    <version>2.33.0</version>
</dependency>

For Jakarta Messaging 3

<dependency>
    <groupId>org.apache.activemq</groupId>
    <artifactId>artemis-ra</artifactId>
    <version>2.33.0</version>
</dependency>

once you have downloaded the resource adapter you would configure Liberty to know about the location of the resource adapter:

  <resourceAdapter id="artemisMQ" location="/path/to/downloaded/artemis.rar" />

Then to configure a JMS Connection Factory you would use configuration like this:

  <jmsConnectionFactory jndiName="jms/artemisCF" >
    <properties.artemisMQ connectionParameters="" />
  </jmsConnectionFactory>

The properties element under the jmsConnectionFactory must end with the id from the resourceAdapter element. The configuration for the properties element is defined by the Artemis RA and I found some documentation at apache for what those are.

Liberty has other elements for configuring jmsQueue, jmsTopic and jmsActivationSpec that follow a similar pattern.

inad9300 commented 5 months ago

I suspect you got the versions wrong and "artemis-ra" corresponds to JMS 2 while "artemis-jakarta-ra" corresponds to Jakarta Messaging 3, right?

That aside, I'm a bit lost as to how to go from the "artemis-jakarta-ra" Maven dependency to a RAR file accessible by Open Liberty. Is there anything you can share about this?

Finally, to use it, is this how I would do it?

@Resource(name = "jms/artemisCF")
private ConnectionFactory connectionFactory;

Is enabling <feature>jndi-1.0</feature> via server.xml necessary?