在我的RabbitMQ RPC应用程序中,每发布一条消息,我就使用一个RabbitMQ连接和通道。因此,一旦消息得到响应,通道就会关闭。非常简单的应用程序。
即使我关闭了通道(我监视了运行时日志并确保所有通道都已关闭),AutorecoveringChannel对象实例仍在内存中收集和增长。我不知道为什么会这样。由于我希望RabbitMQ客户端在关闭通道后会擦除所有数据和通道。
我在Google和其他地方进行了搜索,以了解原因,但是每篇文章都只是在说要关闭它。想出一个主意,请查看此成长对象的VisualVM结果屏幕快照。
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
* {
box-sizing: border-box;
}
body {
font-family: Arial, Helvetica, sans-serif;
}
h2 {
color: white;
}
/* Style the header */
header {
background-color: #2B547E;
padding: 30px;
text-align: center;
font-size: 35px;
color: white;
}
/* Create two columns/boxes that floats next to each other */
nav {
float: left;
width: 30%;
height: 300px;
/* only for demonstration, should be removed */
background: #43BFC7;
padding: 20px;
}
/* Style the list inside the menu */
nav ul {
list-style-type: none;
padding: 0;
}
article {
float: left;
padding: 20px;
width: 70%;
background-color: #f1f1f1;
height: 300px;
/* only for demonstration, should be removed */
}
/* Clear floats after the columns */
section:after {
content: "";
display: table;
clear: both;
}
/* Style the footer */
footer {
background-color: #2B3856;
padding: 10px;
text-align: center;
color: white;
}
/* Responsive layout - makes the two columns/boxes stack on top of each other instead of next to each other, on small screens */
@media (max-width: 600px) {
nav,
article {
width: 100%;
height: auto;
}
}
</style>
<header>
<h2>Voice of the Theatre</h2>
<img src="http://pngimg.com/uploads/world_map/world_map_PNG14.png" width="100px" height="60px">
</header>
<section>
<nav>
<ul>
<li><a class="one" href="#">EMEAR</a></li>
<li><a class="two" href="#">AMER</a></li>
</ul>
</nav>
<article>
<h1>London</h1>
<div id="pchange">
</div>
<ul>
<li>Update 1 </li>
<li>Update 2</li>
<li>Update 3</li>
</ul>
<h1>America</h1>
<ul>
<li>Update 1 </li>
<li>Update 2</li>
<li>Update 3</li>
</ul>
</article>
</section>
<footer>
<p></p>
</footer>
这是我在通过网络套接字收到的每条消息中创建频道的方式
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
消息回复后,我正在getConsumer()中关闭通道。
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());
closeChannel就是channel.close()。
如果您能猜出这里发生的一切,请与我分享您的想法。即便是能使我在此记忆问题上走上正确路的小建议,也很受欢迎。