Reputation: 7736
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
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