Search code examples
javaspring-bootrabbitmqspring-cloud-configspring-cloud-stream

spring cloud bus - rename rabbitmq queues?


Is there a way to tell spring bus to rename its rabbitmq queues? On startup they seem to be just some random values like so:

springCloudBus.anonymous.4zzIP0z-TH6oIza5mCun7Q

trying to get spring bus to rename this to a more human readable predictable queue name. For example:

testQueue

or something with knowledge to what service it's holding messages for.

Ive tried adding the following to the application.yml on for bootRun:

spring:
   cloud: 
     stream:
       bindings:
         output:
           destination: testQueue

with no avail. Please help!!


Solution

  • NOTE: anonymous groups are essential for Spring Cloud Bus to work properly.

    using a group makes

    a) the subscription durable which means that apps will receive all events (including the ones that have been sent while they were not running)

    b) using groups means that apps can become competing consumers which means that the events are not broadcast

    c) queues are not deleted automatically anymore

    The destination you set in spring-cloud-bus inbound/outbound channels are the rabbitmq exchanges not the queues.

    For spring-cloud-bus the outbound channel name is springCloudBusOutput.

    Hence, your configuration needs to be: spring: cloud: stream: bindings: springCloudBusOutput: destination: testExchange Here the destination name testExchange is the exchange name not the queue name. To avoid anonymous name in the queue, you can set a group name for inbound channel binding.

    spring: cloud: stream: bindings: springCloudBusInput: destination: testExchange group: testQueue

    This will make the queue name testExchange.testQueue