java - RabbitMq AutorecoveringChannels 被收集在内存中,即使它们在代码中被关闭
问题描述
在我的 RabbitMQ RPC 应用程序中,每发布一条消息,我都使用一个 RabbitMQ 连接和通道。因此,一旦消息得到结果响应,通道就会关闭。非常简单的应用程序。
即使我关闭了通道(我监控了运行时日志并确保所有通道都已关闭),但 AutorecoveringChannel 对象实例仍被收集并在内存中增长。我不确定为什么会这样。因为我希望 RabbitMQ 客户端在通道关闭后擦除所有数据和通道。
我在谷歌和任何地方搜索都知道为什么,但每篇文章都在告诉我要关闭频道。对于一个想法,请查看这个 VisualVM 结果的增长对象的屏幕截图。
Object instances
com.rabbitmq.client.impl.recovery.AutorecoveringChannel 249
com.rabbitmq.client.impl.recovery.RecordedQueue 502
com.rabbitmq.client.impl.recovery.RecordedQueueBinding 502
com.rabbitmq.client.impl.recovery.RecoveryAwareChannelN 255
这就是我在通过网络套接字接收到的每条消息中创建通道的方式
Channel channel = rabbitMqController.getRmqConnection().createChannel();
//some code
DefaultConsumer consumer = getConsumer(methodCall, channel, callbackFunction);
//some code
channel.basicConsume(replyQueueName, true, consumer);
channel.basicConsume(statusReplyQueueName, true, consumer);
channel.basicPublish(WorkerConfig.getInstance().getWorkerExchangeName(), methodCall.getMethod(), true, props,
methodCall.toJson());
在 getConsumer() 中,一旦消息响应,我就会像这样关闭频道。
return new DefaultConsumer(channel) {
@Override
public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties,
byte[] body) throws IOException {
closeChannel(channel);
//handling code goes here
}
closeChannel 就是 channel.close()。
如果您能猜到这里发生的任何事情,请与我分享您的想法。即使是小的建议也会让我在这个内存问题上走上正轨,我们很高兴欢迎。
解决方案
推荐阅读
- flutter - Flutter - 文本字段覆盖的列表视图的最后一个元素
- android - Google Play 应用签名流程证书
- python - Python在等待函数执行时使循环继续
- .net - Azure devops 测试任务:如何在 Visual Studio 测试执行期间显示消息
- c - 在 Raspbian 中分叉进程时进行调试
- c - 计算总和时得到“1.#INF00” 1!/n^1 + 2!/n^2 + ... + n!/n^n
- javascript - 为什么我的 Redux 道具对象返回未定义?
- php - 用户池客户端 {id} 不存在
- java - 我的代码有什么问题。Decryption.txt 不接受 java 文件操作中的任何消息。?
- javascript - 如何在 Chrome 浏览器中使用 javascript 验证有效的 Date 对象