From the RabbitMQ docs, a message is received asynchronously using @RabbitListener
endpoint:
"The easiest way to receive a message asynchronously is to use the annotated listener endpoint infrastructure. In a nutshell, it allows you to expose a method of a managed bean as a Rabbit listener endpoint."
@RabbitListener(queues = "myQueue")
public void processOrder(String data) {
...
}
What does receiving asynchronously mean here exactly? What is the effect of using blocking calls, e.g. synchronous HTTP inside of the processOrder(...)
function above, given the definition of receiving asynchronously
?
asynchronously mean here that you don't invoke that method directly, instead, some background service will call it at some moment of time which is not controlled by you. On which thread this method will be called, depends on configuration of that service. Usually such services use a thread pool.
The effect of using blocking calls inside asynchronous methods is the thread the method runs on is blocked and cannot serve other asynchronous invocations. If the thread pool behind the asynchronous service has limited number of threads, then so called "thread starvation" may happen and new asynchronous calls cannot be processed. Otherwise, if the thread pool is unlimited, it could consume all available memory because each thread requires 0.5-1 MB for its call stack. To avoid such negative consequences, the asynchronous service must be constructed with throughput high enough to bear expected load, and in case of heavy load, precautions should be taken for the service to degrade gracefully and not crash the whole JVM with OOM.