Rabbit spring cloud stream bind topics to single queue

Viewed 559

Is it possible to bind multiple topics from an exchange to single queue? For example I have producer which declares an exchange and sends three topics log.verbose, log.info, log.error

And I would like to have two consumers which declare own queue and bind to exchange. First consumer subscribes first two topics log.verbose and log.info and another one subscribes all topics.

Is it possible to define config for consumer 1 something like this?

spring.cloud.stream.bindings.input.destination=log
spring.cloud.stream.rabbit.bindings.input.consumer.bindingRoutingKey=log.info,log.verbose

enter image description here

1 Answers

You can not currently do it through property configuration, but you can add the second binding yourself, either manually on the management UI, or by adding Exchange, Queue and Binding @Beans to the application. You can't simply add the second @Binding bean since the queue won't exist yet when the RabbitAdmin (when the application is first started and no queue exists).

See Configuring the broker in the Spring AMQP reference manual.

This technique won't work for anonymous consumers (no ...group property specified for the input) since the queue name is not known.

Related