0
votes

I'm building a SpringCloud Stream based application and exchange type is topic and message is sent to 2 queue consumer groups from the topic exchange. The scenario is something like this:

Service A in my application wants to send message of type appointments to service B and service C via an exchange named as: appointments-request based on different use case scenarios such as book, cancel, update etc.

So messages with a key appointments.book.B or appointments.cancel.B should go to consumer queue group appointments.B

messages with a key appointments.book.C or appointments.cancel.C should go to consumer queue group appointments.C

How to achieve this successfully?

Configuration of Producer Service:

spring.cloud.stream.bindings.output.destination=appointments-request
spring.cloud.stream.bindings.input.destination=appointments-reply
spring.cloud.stream.rabbit.bindings.output.producer.exchangeType=topic
spring.cloud.stream.rabbit.bindings.output.producer.routingKeyExpression= 
 appointments.#.#

Configuration of Consumer Service B:

spring.cloud.stream.rabbit.bindings.input.consumer.exchangeType=direct
spring.cloud.stream.rabbit.bindings.input.consumer.group=
appointments.docmgmt
spring.cloud.stream.rabbit.bindings.input.consumer.bindingRoutingKey=
appointments.docmgmt
spring.cloud.stream.rabbit.bindings.input.consumer.routingKeyExpression= 
appointments.#.docmgmt

Producer Service A has the below method to set routing key

    public boolean send(AppointmentEvent appointmentEvent) 
    {
       logger.info("Sending event {} ",appointmentEvent);
       return this.source.output().
       send(MessageBuilder.withPayload(appointmentEvent).
       setHeader(SimpMessageHeaderAccessor.DESTINATION_HEADER, 
       "appointments.book.docmgmt").build());
     }

My communication between services is not working.

1

1 Answers

1
votes

appointments.#.#

You can't use wildcards on the producer side.

You need something like

spring.cloud.stream.rabbit.bindings.output.producer.routingKeyExpression=headers['routingKey']

And then the producer sets the routingKey header to the desired value for each message.

You shouldn't really use the Simp headers; that is for STOMP; use your own header.