Queues are vital in messaging and naming them appropriately is even more crucial to easily identify the application context and business purpose it serves. If you are using Solace tools directly, you can name them as needed and appropriate. In this blog we will discuss how to customize queue names when using Spring Cloud Stream with the Solace Binder.

By default, the Solace Spring Cloud Stream binder provides an opinionated queue naming scheme that uses contextual information around a queue like familiarity, destination encoding, and destination name.

Here is the convention followed by the Spring Cloud Stream binder for Solace PubSub+.
For eueues:

<prefix>/<familiarity-modifier>/<group>/<destination-encoding>/<encoded-destination>

For error queues:

<prefix>/error/<familiarity-modifier>/<group>/<destination-encoding>/<encoded-destination>

This expression is evaluated based on the values set for these attributes in the configuration file.

  • prefix: A static prefix as indicated by the queueNamePrefix configuration option.
  • familiarity-modifier: Indicates the durability of the consumer group (wk for well-known or a for anonymous). Can be enabled/disabled with the useFamiliarityInQueueName config option.
  • group: The consumer group name. Can be enabled/disabled for consumers with the useGroupNameInQueueName (deprecated) consumer config option.
  • destination-encoding: Indicates the encoding scheme used to encode the destination in the queue name (currently, only plain is supported). Can be enabled/disabled with the useDestinationEncodingInQueueName config option.
  • encoded-destination: The encoded destination name as per <destination-encoding>

Note that these attributes are deprecated, but they carry a default value and are utilized in the absence of custom queue name rules.

If you don’t already have a queue naming convention in place at your organization then the default naming convention sets you up for success. However, sometimes organizations have their own naming conventions in place, and you need the ability to customize these names.

Custom Names using SpEL Expression

Since v3.3.0 of the Solace Spring Cloud Stream Starter, which is usually included using v2.3.0 of the Solace Spring Cloud BOM, you can specify custom names for queues and error queues using queueNameExpression and errorQueueNameExpression properties in the Spring Cloud Configuration file. The value for these properties can be an expression based on SpEL (Spring Expression Language). The expression shall refer to set context variables in the Spring Cloud Configuration.

Since we are using SpEL the possibilities are endless and really put the power of custom queue naming in the hands of the developer. Keep it simple or make it as complex as you’d like. For example, the default SpEL expression for creating the consumer group’s queue name is defined as follows:

(properties.solace.queueNamePrefix?.trim()?.length() > 0 ? 
    properties.solace.queueNamePrefix.trim() + '/' : '') + 
(properties.solace.useFamiliarityInQueueName ? 
    (isAnonymous ? 'an' : 'wk') + '/' : '') + 
(isAnonymous ? group?.trim() + '/' : 
    (properties.solace.useGroupNameInQueueName ? 
        group?.trim() + '/' : '')) + 
(properties.solace.useDestinationEncodingInQueueName ? 'plain' + '/' : '') +
destination.trim().replaceAll('[*>]', '_')

By having that as the default it maintains the same queue naming convention that the binder established in previous versions, and as stated earlier in this blog.

<prefix>/<familiarity-modifier>/<group>/<destination-encoding>/<encoded-destination>

So how do you harness this power? Let’s learn about SpEL.

About SpEL

The Spring Expression Language (SpEL for short) is a powerful expression language that supports querying and manipulating an object graph at runtime. The language syntax is similar to Unified EL but offers additional features, most notably method invocation and basic string templating functionality. The Spring Expression Language was created to provide the Spring community with a single well-supported expression language that can be used across all the products in the Spring portfolio. In Solace Binder, we can use the SpEL to specify queue name expressions to generate custom queue names.

Let’s look at two examples of custom queue naming using SpEL. One that uses other properties in the config file and another that allows you to just specify a literal.

First let’s take a look at using other properties from the config file as part of our queue name. Consider the following solace binding configuration in a Spring Cloud Stream configuration file.

stream:
  bindings:
    uppercase-in-0:
      destination: manualackqueue
      binder: solace-broker
      group: myconsumergroup
...
solace:
  bindings:
    uppercase-in-0:
      consumer:
        queueNamePrefix: 'QNAME-'
        queueNameExpression: "'CUSTOM-' + (properties.solace.queueNamePrefix.trim() + '-) + (properties.solace.useGroupNameInQueueName ? group?.trim() + '-' : '')) + (properties.solace.useDestinationEncodingInQueueName ? 'plain' + '-' : '') + destination.trim().replaceAll('[*>]', '-')”
        errorQueueNameExpression: "'ERROR-' + (properties.solace.queueNamePrefix.trim() + '-) + destination.trim().replaceAll('[*>]', '-')"
        provisionErrorQueue: true
        autoBindErrorQueue: true

This will produce a custom queue name CUSTOM-QNAME-wk-myconsumergroup-manualackqueue and an error queue name ERROR-QNAME-manualackqueue.

You can also specify a literal name as the queue name in queueNameExpression property. The SpEL expects literal names to be quoted, and the quotes need to be escaped.

queueNameExpression: ‘’’solace/just/a/literal/queuename’’’

This will produce a custom queue name solace/just/a/literal/queuename.

With the provisionQueueName and provisionErrorQueue flags set to true, this will produce queues with names –
producing queues with names in PubSub+

Queue Name:
queue details in PubSub+

Error Queue Name:
error queue name details in PubSub+

Generated Literal Queue name (hard-coded):
Generated Literal Queue name in PubSub+

Summary

As a developer, this feature empowers you to generate custom names for queues and error queues when using Spring Cloud Stream binder for Solace PubSub+.

If you’re new to Spring Cloud Stream and would like more help getting up and running these are great places to check out for more tutorials.

And last, but not least, is our Solace Community, where developers and experts hang out exchanging notes, sharing thoughts, and discussing related topics. Join the community and enjoy the perks of knowledge sharing.

Giri Venkatesan
Giri Venkatesan

Giri is a developer advocate with extensive experience in various technical domains, including integration and master data management. He started his engineering journey in the classic EAI & B2B Integration space and has been a part of the integration evolution culminating in modern EDA, microservices, Spring, and other low-code/no-code frameworks. He has a keen interest in building and promoting creative solutions and is a huge fan of open-source standards and applications. He is excited to identify and explore tools and frameworks to aid businesses in their quest for achieving efficiency and increased productivity.