Web User
Web User

Reputation: 7736

Autowiring of exchange, queue and binding with Spring AMQP + RabbitMQ (Spring Boot)

In the Spring docs for Messaging with RabbitMQ, rabbitTemplate, queue, exchange and binding are all set up by Spring Boot. What I don't understand is how rabbitTemplate.convertAndSend(...) sends it to the created exchange, since the method call does not specify an exchange and it includes only the routing key (via the queue name) and the message itself - which I thought implicitly sends the message to the default exchange and not the created exchange. The message will reach the intended queue since the routing key matches the name of the queue.

If I wanted to specify the exchange and routing key, using this API method:

// Convert a Java object to an Amqp Message and send it to
// a specific exchange with a specific routing key.
convertAndSend(String exchange, String routingKey, Object object);

... how do I get a reference to the created exchange?

Thanks.

Upvotes: 1

Views: 2937

Answers (1)

Gary Russell
Gary Russell

Reputation: 174574

Boot's RabbitAutoConfiguration only registers the connection factory, a RabbitAdmin a RabbitTemplate and a RabbitMessagingTemplate.

That guide declares its own exchange, queue, and binding.

You can simply @Autowire the exchange as normal and call getName().

Upvotes: 3

Related Questions