I'm developing an application that uses RabbitMq with Micronaut(v1.1.3) Framework, the goal of this application is to write on the queue the path of a file. The workers (RabbitListeners) consume the queue and do certain operations on the indicated file. These operations can be burdensome and therefore I don't want the queue to immediately assign messages to the first available worker so as to avoid overloading a worker. I have read that you need to set the "prefetch_count" to prevent the worker from being overloaded. The problem is that channel.basicQos (1) is completely ignored and therefore the prefetch_count is not set in the queue.
@Singleton
public class ChannelPoolListener extends ChannelInitializer {
@Override
public void initialize(Channel channel) throws IOException {
channel.basicQos(1);
channel.exchangeDeclare("micronaut", BuiltinExchangeType.DIRECT, true);
channel.queueDeclare("log", true, false, false, null);
channel.queueBind("log", "micronaut", "log");
}
}
The channel passed in the initializer has no guarantees to be used beyond that scope. You need to set the prefetch in the Queue
annotation. See https://micronaut-projects.github.io/micronaut-rabbitmq/latest/api/io/micronaut/configuration/rabbitmq/annotation/Queue.html#prefetch--