I'm using Java RabbitMQ Client. I publish a message (basicPublish) and then I close channel. In Consumer, channel.basicAck throw exception:
com.rabbitmq.client.AlreadyClosedException: connection is already closed due to connection error; cause: java.util.concurrent.RejectedExecutionException: Task com.rabbitmq.client.impl.ConsumerWorkService$WorkPoolRunnable@665de7c7 rejected from java.util.concurrent.ThreadPoolExecutor@35f53993[Running, pool size = 5, active threads = 5, queued tasks = 0, completed tasks = 5]
If delete channel.close(), the error doesn't reproduced. Why connection closed, when I close the channel?
Sent messages to exchange:
Channel channel = connection.createChannel();
Set<String> expectedMessages = new HashSet<>(MESSAGES_COUNT);
for (int i = 0; i < MESSAGES_COUNT; i++) {
String message = Integer.toString(i);
channel.basicPublish(
TEST_EXCHANGE,
ROUTE_KEY,
TEXT_PLAIN,
message.getBytes("UTF-8")
);
expectedMessages.add(message);
}
channel.close();
Consumer:
try {
channel.basicAck(deliveryTag, false);
} catch (Exception e) {
log.error("Error during message handling: " + consumerTag, e);
channel.basicNack(deliveryTag, false, true);
}