Using JMS 2.0 APIs to access Azure Service Bus

[Created on 12 August, 2020, and updated on 22 January, 2021]

Japanese edition is here.
https://logico-jp.io/2020/08/12/using-jms-2-0-apis-to-access-azure-service-bus/

As you may know, support for JMS 2.0 APIs on Azure Service Bus Premium Tier is generally available. This feature allows us to interact with Azure Service Bus through JMS over AMQP 1.0.

As of 22 January, 2021, “preview” still exists in the document title, but it will be modified shortly.

Note that the following document title is similar to the previous one, but this document does not cover JMS 2.0 APIs but JMS 1.1 APIs in Standard tier.

In fact, we can use JMS 1.1 APIs to connect Azure Service Bus standard tier, but support for JMS 1.1 APIs is limited as you see the warning message in the document.

Which tier of Azure Service Bus supports JMS 2.0 APIs?

Premium tier only supports JMS 2.0 APIs. If using JMS 2.0 APIs to interact with Azure Service Bus Standard or Basic tier, the following exception is thrown with the message of “Full JMS 2.0 parity over AMQP is a feature supported only by a Premium Messaging namespace”.

Which JMS features are supported?

You can find supported features in the following URL. Note that distributed transaction is not supported.

Dependencies

As of 22 January, 2021, the latest version is 0.0.7. Please check the latest one in maven central repository. You can either use jar file to build your applications, or resolve dependencies through Maven or Gradle.

Here is a snippet of pom.xml.

Give it a try!

Following the document pointed earlier, you can do it easily. Let me show you examples using .

First of all, connection factory should be instantiated in Azure Service Bus specific manner.

Then, application(s) can be implemented in the usual manner of JMS 2.0 APIs. The following snippet is an example to send a text message to a queue.

The next snippet is an example to receive text messages from a queue.

Here is a code for message listener used in the sample listed above. It is pretty simple since it is used for checking messages only.

Subscription name scheme

In case of using topic, we have generally to subscribe a topic in order to wait for messages and creating subscription in advance is required. If not created yet, a subscription is automatically created when creating a object and generated subscription is deleted when closing object. As of January 10, 2021, subscription name is generated with the following scheme.

1. JMSContext::createConsumer

In case of method, subscription name is created as follows.

$ is a delimiter, and “ND” would stand for “non durable”. As method doesn’t have any way to specify subscription name, GUID is used as an alternative subscription name. Even if setting to Jobject, the specified is not used in the subscription name.

2. JMSContext::createDurableConsumer

In case of method, subscription name is created as follows.

$ is a delimiter, and “D” would stand for “durable”. Both and are mandatory and should be set to object in the application. As you know, calling method without specified result in IllegalStateRuntimeException.

3. JMSContext::createSharedConsumer

In case of method, subscription name is created as follows.

$ is a delimiter, and “ND” would stand for “non durable”. And is mandatory, while c is optional.

So, two delimiters “$$” can be found in a subscription name when calling method without specified.

4. JMSContext::createSharedDurableConsumer

With specified, subscription name is created as follows ( is mandatory).

$ is a delimiter, and “D” would stand for “durable”. This scheme is the same as the scheme of .

Without specified, subscription name is created as follows ( is mandatory).

What benefits for you?

When migrating existing Java applications running on application servers to cloud, some customers tend to choose “lift to IaaS” strategy rather than “modernization”. Such customers tend to describe the reasons why they made such decisions.

If a managed message broker is required, JMS 2.0 APIs are used in existing applications, and you have a plan to modernize your applications running on application servers, Azure Service Bus might fit you. Furthermore, if you are familiar with JMS 2.0 APIs, you don’t have to spend lots of time to learn how to develop applications with Azure Service Bus.

Conclusion

I confirmed Java application could interact with Azure Service Bus through JMS 2.0 APIs.

My sample codes are available on GitHub.

Cloud Solution Architect @Microsoft, focusing on Application Development. ❤️Java (JVM/GraalVM) and open source technologies. All views are my own. Ex-🥑.