Configuring multiple queues with a topic exchange and using routing key to direct the message specific queue with spring cloud streams

My requirement is example I have the queues and exchange defined as below in consumer end

spring.cloud.stream.bindings.inputA.destination=Common-Exchange
spring.cloud.stream.bindings.inputA.group=A-Queue

spring.cloud.stream.bindings.inputB.destination=Common-Exchange
spring.cloud.stream.bindings.inputB.group=B-Queue
  • I should be able to specify the routing key in the consumer just like we do it in AMQP where we can pass the exchange queue and routing key to create the binding
  • I should be able to set the routing key when sending the message in producer end using MessageBuilder

    channel.send(MessageBuilder.withPayload(message).build())

Of course we can use one queue and use headers to direct different type of messages but I need to know how multiple queue connected to a single exchange work with streams.

1 Answers

1
Gary Russell On Best Solutions

See the Rabbit binder documentation.

  • On the consumer side, set the bindingRoutingKey consumer binding property.
  • On the producer side, the the routingKeyExpression producer binding property (e.g. headers['routingKey'] and set that header as needed).

Also see Using Existing Queues/Exchanges.