How does RocketMQ store messages?

RocketMQ utilizes two methods to save messages:

  1. Synchronous flushing: When a message producer sends a message, RocketMQ immediately writes the message to disk and waits for the disk I/O operation to complete before returning a successful result to the producer. This method ensures that the message is not lost after being written to disk, but it can affect the speed of message delivery.
  2. Asynchronous flushing: When a message producer sends a message, RocketMQ will write the message to disk in the background thread without waiting for the disk IO operation to complete. This method can increase the message sending speed but also raises the risk of message loss.

RocketMQ also offers message persistence strategy configuration, allowing users to choose the appropriate strategy based on their actual business needs. By default, RocketMQ saves messages using synchronous flushing. Users can switch between synchronous and asynchronous flushing by modifying the flushDiskType parameter in the broker configuration file.

bannerAds