RabbitMQ 实际是如何物理存储消息的? [英] How does RabbitMQ actually store the message physically?

查看:28
本文介绍了RabbitMQ 实际是如何物理存储消息的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道 RabbitMQ 如何将消息物理存储在其 RAM 和磁盘中?

I want to know how does RabbitMQ store the messages physically in its RAM and Disk?

我知道 RabbitMQ 试图将消息保存在内存中(但我不知道消息是如何放入 Ram 中的).但是当消息处于持久模式或代理有内存压力时,消息可能会溢出到磁盘中.(但我不知道消息是如何存储在磁盘中的.)

I know that RabbitMQ tries to keep the messages in memory (But I don't know how the messages are put in the Ram). But the messages can be spilled into disk when the messages are with persistent mode or when the broker has the memory pressure. (But I don't know how the messages are stored in Disk.)

我想了解这些的内部情况.不幸的是,其主页上的官方文档并没有公开内部细节.

I'd like to know the internals about these. Unfortunately, the official documentation in its homepage do not expose the internal details.

我应该为此阅读哪个文件?

Which document should I read for this?

推荐答案

RabbitMQ 使用自定义 DB 来存储消息,该 db 通常位于此处:

RabbitMQ uses a custom DB to store the messages, the db is usually located here:

/var/lib/rabbitmq/mnesia/rabbit@hostname/queues

从 RabbitMQ 3.5.5 版本开始引入了新的新信用流https://www.rabbitmq.com/blog/2015/10/06/new-credit-flow-settings-on-rabbitmq-3-5-5/

Starting form the version 3.5.5 RabbitMQ introduced the new New Credit Flow https://www.rabbitmq.com/blog/2015/10/06/new-credit-flow-settings-on-rabbitmq-3-5-5/

我们来看看 RabbitMQ 队列是如何存储消息的.当一个消息进入队列,队列需要判断消息是否应该坚持还是不坚持.如果消息必须被持久化,那么RabbitMQ 将立即这样做[3].现在即使消息被保留到磁盘,这并不意味着消息已从 RAM 中删除,因为RabbitMQ 在 RAM 中保留消息缓存,以便在以下情况下快速访问向消费者传递消息.每当我们谈论分页时将消息发送到磁盘,我们正在讨论 RabbitMQ 在必须将此缓存中的消息发送到文件系统.

Let’s take a look at how RabbitMQ queues store messages. When a message enters the queue, the queue needs to determine if the message should be persisted or not. If the message has to be persisted, then RabbitMQ will do so right away[3]. Now even if a message was persisted to disk, this doesn’t mean the message got removed from RAM, since RabbitMQ keeps a cache of messages in RAM for fast access when delivering messages to consumers. Whenever we are talking about paging messages out to disk, we are talking about what RabbitMQ does when it has to send messages from this cache to the file system.

这篇博文已经够详细了.

This post blog is enough detailed.

我还建议阅读惰性队列:https://www.rabbitmq.com/lazy-queues.htmlhttps://www.rabbitmq.com/blog/2015/12/28/whats-new-in-rabbitmq-3-6-0/

I also suggest to read about lazy queue: https://www.rabbitmq.com/lazy-queues.html and https://www.rabbitmq.com/blog/2015/12/28/whats-new-in-rabbitmq-3-6-0/

惰性队列 这种新型队列的工作原理是发送每一条消息直接传递给他们的文件系统,并且只加载当消费者到达队列时,RAM 中的消息.优化磁盘读取消息是分批加载的.

Lazy Queues This new type of queues work by sending every message that is delivered to them straight to the file system, and only loading messages in RAM when consumers arrive to the queues. To optimize disk reads messages are loaded in batches.

这篇关于RabbitMQ 实际是如何物理存储消息的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆