概述
我正在使用Java RabbitMQ Client . 我发布了一条消息(basicPublish),然后我关闭了 Channels . 在Consumer中,channel.basicAck抛出异常:
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]
如果删除channel.close(),则不会再现错误 . 当我关闭 Channels 时,为什么连接关闭?
发送消息进行交换:
Channel channel = connection.createChannel();
Set 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();
消费者:
try {
channel.basicAck(deliveryTag, false);
} catch (Exception e) {
log.error("Error during message handling: " + consumerTag, e);
channel.basicNack(deliveryTag, false, true);
}
最后
以上就是平淡芒果为你收集整理的java怎么关闭channel_调用channel.close()后关闭RabbitMQ连接的全部内容,希望文章能够帮你解决java怎么关闭channel_调用channel.close()后关闭RabbitMQ连接所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复