Search code examples
rabbitmqspring-cloud-streamspring-rabbit

Apply a dynamic group value in Spring Cloud Stream


How could I give a group value to the stream binders dynamically, for flexibility while using Spring Cloud Stream. How can I achieve this?


Solution

  • Spring Boot configuration properties can use property placeholder to be based on other properties or environment variables.

    So, the mentioned spring.cloud.stream.bindings.<bindingName>.group can be something like this:

    spring.cloud.stream.bindings.MY_INPUT_QUEUE.group=${my.envvar}
    

    This way you can rely on something what is relevant to the environment where your service has started.

    See more in docs: https://docs.spring.io/spring-boot/docs/current/reference/html/features.html#features.external-config.files.property-placeholders