Custom Queue Names when using Spring Cloud Stream binder for Solace PubSub+

Options
giri
giri Member, Administrator, Employee Posts: 104 admin
edited September 2022 in General Discussions #1

The Spring Expression Language (SpEL for short) is a powerful expression language that supports querying and manipulating an object graph at runtime. In Solace Binder, we can use the SpEL to specify queue name expressions to generate custom queue names.

Not all properties present in the application configuration are available for use while constructing a SpEL expression. Here is a list of supported context variables available for use in the expression.

The properties.solace and properties.spring throws open all the properties defined spring.cloud.stream.bindings.<binder_name>.consumer and spring.cloud.stream.solace.bindings.<binder_name>.consumer for use in the SpEL expression.

Consider an example configuration.

spring:
  cloud:
    function:
      definition: uppercase
    stream:
      bindings:
        uppercase-in-0:
          destination: manualackqueue
          binder: solace-broker
          group: myconsumergroup
          consumer:
            concurrency: 1
            max-attempts: 3
        uppercase-out-0:
          destination: uppercase/topic
          binder: solace-broker
      binders:
        solace-broker:
          type: solace
          environment:
            solace:
              java:
                host: 'tcp://xxxx:55554'
                msgVpn: default
                clientUsername: default
                clientPassword: default
                connectRetries: -1
                reconnectRetries: -1
      solace:
        bindings:
          uppercase-in-0:
            consumer:
              provisionDurableQueue: true
              queueNamePrefix: QNAME
              errorMsgTtl: 10000
              queueNameExpression: "'QUEUE-' + \
                properties.solace.queueNamePrefix.toString() + '-' + \
                properties.spring.concurrency.toString() + '-' + \
                properties.spring.maxAttempts.toString() + '-' + \
                properties.solace.errorMsgTtl.toString() + '-' + \
                (properties.solace.provisionDurableQueue ? 'AUTO' : 'MANUAL')" 

This will produce the following custom queue name:

QUEUE-QNAME-1-3-10000-AUTO

Note: Custom properties are not supported in the SpEL expression.

For more information on custom names for queues and error queues, refer to this blog Custom Name for your Queues when using Spring Cloud Stream Binder for Solace PubSub+