- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我目前正在运行一个基本的 RabbitMQ 主题发布,每 3 秒发布一次。
我的类(class)是这样的:
import com.rabbitmq.client.*;
import java.io.IOException;
public class EmitLogTopic {
private static final String EXCHANGE_NAME = "topic_logs";
@Scheduled(fixedRate = 3000)
public void publish(String[] argv)
throws Exception {
ConnectionFactory factory = new ConnectionFactory();
factory.setHost("localhost");
Connection connection = factory.newConnection();
Channel channel = connection.createChannel();
channel.exchangeDeclare(EXCHANGE_NAME, "topic");
String routingKey = getRouting(argv);
String message = getMessage(argv);
channel.basicPublish(EXCHANGE_NAME, routingKey, null, message.getBytes());
System.out.println(" [x] Sent '" + routingKey + "':'" + message + "'");
channel.close();
connection.close();
}
//...
}
我希望每次运行 publish 方法时,它都会发布,然后 channel 和连接都关闭,以防止新 channel 和连接每 3 秒卡在内存中。
但是,当我查看我的 RabbitMQ 管理界面(在概览页面)时,“全局计数”部分显示连接总数和 channel 总数都在不断增加。
最终,由于达到套接字限制和内存限制,我的应用程序崩溃了。
所以看起来 close() 并没有删除使用的 channel 和连接,而是仍然将它们保留在内存中,最终导致所有内存被消耗。在 channel 和连接上使用什么正确方法来确保他们不会这样做?
最佳答案
However, when I look at my RabbitMQ admin interface (at the overview page), the Global Counts section shows that both the total number of connections and channels keep on increasing.
我认为你的连接有问题。
检查操作系统中的 TCP 连接,例如:
1. 网络统计-anp | grep:5672 | grep 已建立 | wc -l
同时使用命令行工具检查您的连接:
如果您在
2. rabbitmqctl 列表连接1
和 2
中有很多连接,则意味着您没有以正确的方式关闭连接/ channel 。
如果您需要处理大量连接,您可以增加文件描述符配置:
例如https://www.rabbitmq.com/install-debian.html
使用 systemd(最近的 Linux 发行版)
On distributions that use systemd, the OS limits are controlled via a configuration file at /etc/systemd/system/rabbitmq-server.service.d/limits.conf, for example:
[Service] LimitNOFILE=300000
编辑
您发布的代码很好,close()
方法是关闭连接的正确方法。
如果您执行代码,您应该在您的真实代码中进行调查。
还要检查日志中是否有:
=INFO REPORT==== 22-Aug-2017::09:23:28 ===
connection <0.383.0> ([::1]:60590 -> [::1]:5672): user 'guest' authenticated and granted access to vhost '/'
=INFO REPORT==== 22-Aug-2017::09:23:37 ===
closing AMQP connection <0.383.0> ([::1]:60590 -> [::1]:5672, vhost: '/', user: 'guest')
closing AMQP connection
是关闭连接
关于java - 正确关闭 RabbitMQ channel 和连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45800701/
我想读取 RabbitMQ 队列中未确认消息的负载或 messageId。这可能吗? 我想这样做的原因是我尝试使用 RabbitMQ 死信功能来构建一个循环以定期自动生成消息。简而言之,创建两个队列
除了 vFabric 由 VMWare 提供商业支持之外,vFabric RabbitMQ 和 RabbitMQ 之间的主要区别是什么? 最佳答案 来自 source : We also produc
RabbitMQ 集群中有如下三个节点。 在 RabbitMQ 中,有两个队列,q1 和 q2。 q1 和q2 的主副本分布在不同的节点上。两个队列都被其他节点镜像。 三个节点前面有一个负载均衡器。
我希望在谷歌计算引擎上实现 rabbitmq 来处理我的 android 和 ios 消息传递应用程序上的消息。我听说 rabbitmq 可能非常耗电,所以我想知道解决这个问题的最佳解决方案是什么?我
是否可以在 RabbitMQ 服务器(管理插件 View )中查看连接单元的主机名,而不仅仅是 IP/端口?我们使用动态连接位置,这样更容易识别客户...... 最佳答案 不,没有这样的内置功能。 作
我正在阅读 RabbitMQ in Action 书,仍在第 2 章中,但作者说的一件事让我感到困惑。您设置了一个交换并发送了一条消息,两个订阅者正在监听队列。当第一条消息进来时,第一个订阅者得到它,
我正在使用 RabbitMQ 将所有消息排队,并将消息作为 SMS 发送给各个消费者。我正在使用直接交换,并且我已经正确地创建了一个到带有路由键的队列的绑定(bind)。问题是,当我尝试发布消息时,我
我们正在使用微服务架构在 nodejs 中实现 Web-API。每个服务都会公开 HTTP 端点,以便应用程序/网站可以与其交互。为了同步不同的数据库,我们目前使用 RabbitMQ。微服务可以在扇出
我计划在 RabbitMQ 消息头中存储堆栈跟踪。消息 header 是否有大小限制? 最佳答案 RabbitMQ 默认使用 AMQP 版本 0.9.1。根据AMQP protocol specifi
无法理解 exclusive queue 和 exclusive consumer 之间的区别,想知道我是否理解正确。 假设我有一个 queue、consumer1 和 consumer2。 我的理解
发布到 RabbitMQ 队列(发布/订阅模型)时消息的最大大小是多少? 我在文档中看不到任何明确的限制,但我认为有一些指导方针。 提前致谢。 最佳答案 我在做比较亚马逊队列服务和 RabbitMQ
我可以使用 Publish/Subscribe 创建扇出交换RabbitMQ Java 教程,任何连接的消费者都会收到一条消息的副本。我不想以动态/编程方式声明交换和绑定(bind),而是想在连接任何
java的 native rabbitmq客户端允许在连接设置上设置心跳,例如: import com.rabbitmq.client.ConnectionFactory; ... Connectio
我开始着手一个新项目,我们被要求将系统构建为一系列微服务,使用 RabbitMQ 作为它们之间的通信层。 在开发 REST API 时,我倾向于使用接受 HTTP header 来控制版本控制,我看到
在 Rabbit MQ 中使用集群时,我计划使用竞争订阅者模式。 Producer : 1 Exchange : 1 direct Queue : 1 Consumers : n (multiple)
是否可以实现 aggregator pattern在 RabbitMQ 中? 我有 A … N在发送到另一个队列之前我需要等待/聚合的消息 X . 所以我想我会有一些 唯一 ID 确保消息被路由 独家
我正在使用RabbitMQ向用户发送通知。用户可以随时读取其队列。 我面临的问题是,队列在夜间充满了很多通知,而当用户在早上返回时,他必须顺序处理这些消息。这些通知中有很多甚至是重复的。 我认为在发布
是否可以延迟通过 RabbitMQ 发送消息? 例如,我想在 30 分钟后使客户端 session 过期,并且我发送了一条将在 30 分钟后处理的消息。 最佳答案 您可以尝试两种方法: 旧方法:在每个
RabbitMQ 在单个服务器上可以处理的最大队列数是多少? 这取决于内存吗?它取决于 erlang 进程吗? 最佳答案 RabbitMQ 代理内部没有任何硬编码限制。代理将利用所有可用资源(除非您对
RabbitMQ Server 使用或需要在防火墙上为节点集群打开哪些端口? 我的 /usr/lib/rabbitmq/bin/rabbitmq-env 设置如下,我假设需要 (35197)。 SER
我是一名优秀的程序员,十分优秀!