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 error queues:
This expression is evaluated based on the values set for these attributes in the configuration file.
useGroupNameInQueueName(deprecated) consumer config option.
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.
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.
So how do you harness this power? Let’s learn 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
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.
This will produce a custom queue name
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 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.[position] => [url] => https://solace.com/blog/author/girivenkatesan/ ) )