I'm using Spring Boot 1.3.2 and Spring AMQP (with mostly default configuration) to achieve communication between a set of microservices, and I notice that the first "request" after the startup of each microservice takes a "long" time because it is when the connection to RabbitMQ is created.
Is there any way to force the connection to be created early-on (during the startup phase) instead of being created lazily on the first "request"?
If you are consuming messages then the listener container will establish a connection on startup.
If you are only producing messages then you will see the behavior you describe.
To work around it; create a class that implements SmartLifecycle; @Autowire the connection factory; in the start() method, execute this.connectionFactory.createConnection() and, add a @Bean to the context.
There's no need to "close" the connection (but it won't hurt), it is a single connection that's used for all channels (by default).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With