I have a simple question but I can't find anything about it in the documentation nor any example.
I have a Spring Boot project which uses RabbitMQ and the Spring boot AMQP module.
I'm using a specific exchange, and the Spring Jackson2JsonMessageConverter
so I need to define my own RabbitTemplate
bean, I guess (at this point, if anyone knows if it can be done another simpler way, you are welcome).
@Bean
RabbitTemplate myAwesomeTemplate() {
RabbitTemplate rabbitTemplate = new RabbitTemplate();
rabbitTemplate.setExchange(myBeautifulExchange);
rabbitTemplate.setRoutingKey("legendary");
rabbitTemplate.setMessageConverter(new Jackson2JsonMessageConverter());
rabbitTemplate.setConnectionFactory(connectionFactory());
return rabbitTemplate;
}
The real question for me here is that I have to define a CachingConnectionFactory
bean too, just to set it to the template, but it seems a CachingConnectionFactory
is already defined by the Spring RabbitAutoConfiguration
class, so I was wondering if I could simply do this in my class:
@Autowired
CachingConnectionFactory cachingConnectionFactory
But Intellij keeps complaining because it cannot find the definition of that bean, as if it was some definition order matter or something... When I launch the project that way, it seems ok anyway, but I don't like when Intellij complains, it's like I'm doing something "not the standard way".
Thank you everyone in advance ! Sorry for the long explanation.
PS: same problem if I just want to autowire the Spring RabbitProperties
bean and use the host, username and password properties (respectively spring.rabbitmq.host
, spring.rabbitmq.username
and spring.rabbitmq.password
).