I am new to Spring cloud and RabbitMQ. I am trying to produce and consume messages from Rabbit MQ. I am having difficulty in configuring exchange name and queue name for producer and consumer.
I want to connect to the existing exchange called to order
and the existing queue called myQueue
Below is the application.properties
spring.rabbitmq.addresses=amqp://user:pass@localhost:5672/
spring.cloud.stream.function.bindings.processTable-out-0=order
spring.cloud.stream.function.bindings.processTable-in-0=order
spring.cloud.stream.bindings.order.group=myQueue
spring.cloud.stream.bindings.order.content-type=application/json
Above configuration is connecting to order
exchange, however, it is creating and connecting a new queue called order.myQueue
.
The consumer method is below.
@Bean
public Consumer<String> processTable(){
log.info("Conuming message......................");
Consumer<String> consumer = (request)-> System.out.println(request);
System.out.println(consumer);
return consumer;
}
What do I need to tweak in application.properties
to connect to order
exchange and myOrder
queue?
See Using Existing Queues/Exchanges.
spring.cloud.stream.bindings..destination=myExchange
spring.cloud.stream.bindings..group=myQueue
spring.cloud.stream.rabbit.bindings..consumer.bindQueue=false
spring.cloud.stream.rabbit.bindings..consumer.declareExchange=false
spring.cloud.stream.rabbit.bindings..consumer.queueNameGroupOnly=true