Cloud Native 13 min read

Why Choose RocketMQ? Synchronous Writes, Multi‑Topic Speed, and SPI Extensibility

This article explains the reasons for selecting Apache RocketMQ—its synchronous double‑write safety, strong performance under massive multi‑topic loads, rich features like transactional and delayed messages, active community support, and demonstrates how to leverage Java’s SPI mechanism to build a configurable, dynamically adjustable client architecture.

Alibaba Cloud Native
Alibaba Cloud Native
Alibaba Cloud Native
Why Choose RocketMQ? Synchronous Writes, Multi‑Topic Speed, and SPI Extensibility

01 Why Choose RocketMQ

When evaluating message‑queue solutions, the primary criteria are reliability, performance, feature set, and community support. RocketMQ stands out for several reasons:

Synchronous double‑write for data safety – Messages are persisted to both master and slave brokers before acknowledgment. This guarantees no data loss, with a modest ~20% throughput reduction compared to pure asynchronous writes. In a single‑master‑slave setup, 1 KB messages can still achieve >80 k TPS, and horizontal broker scaling can compensate for any loss.

Strong performance with many topics – In tests writing 1 KB messages to 10 000 random topics, a single broker sustained ~20 k TPS, outperforming Kafka. RocketMQ stores all topics in a single commit‑log file, avoiding the many‑small‑file overhead that degrades Kafka’s multi‑topic throughput.

Rich messaging capabilities – Supports transactional, ordered, delayed, and retry‑on‑failure messages, making it suitable for complex business scenarios.

Active open‑source community – Developed by Alibaba, written in Java, with a vibrant Chinese developer community, facilitating source‑code reading, issue troubleshooting, and custom extensions.

02 SPI Mechanism Overview and Application

RocketMQ leverages Java’s Service Provider Interface (SPI) to allow developers to plug in custom implementations without modifying core code. For example, the default ACL validator implements AccessValidator via PlainAccessValidator. By providing a new implementation of AccessValidator and registering it via the SPI configuration, teams can tailor permission checks to their organization’s needs.

SPI configuration diagram
SPI configuration diagram

03 Client Core Process Details

The client lifecycle is divided into three phases: start‑up, runtime, and shutdown.

Start‑up – Load the unified configuration file (which combines native RocketMQ settings with three custom entries: sendMsgService, consumeMsgConcurrently, consumeMsgOrderly). The configuration is parsed before any producer or consumer objects are instantiated.

Runtime – Initialize producer and consumer instances based on the configuration. A watcher monitors the file for changes; when modifications are detected, the corresponding producers/consumers are recreated or adjusted without restarting the application.

Shutdown – Gracefully close each producer and consumer and remove them from the container. This does not terminate the entire application, only the messaging components that may be dynamically replaced.

Client core flow diagram
Client core flow diagram

04 How to Load the Configuration File

The configuration can be placed alongside other application files for convenience, even though the standard SPI location is META-INF/services. Loading logic supports both legacy projects (JDK 1.6) and modern Spring Boot applications. For Spring Boot, an auto‑configuration module reads the file from the classpath and registers a listener for dynamic updates.

05 Linking Producers/Consumers to Business Logic

Consumers implement a message listener interface; the framework injects the concrete business class defined in the configuration. If the business class is managed by Spring, it is obtained from the Spring context; otherwise, reflection creates the instance.

Producers must extend SendMessage, which provides an RmqProducer wrapper. This wrapper enforces company‑wide naming conventions for topics and standardizes the send‑message API.

06 Dynamic Adjustment Scenarios

Four situations trigger reconfiguration:

Nameserver change – re‑initialize all producers and consumers.

Instance scaling – add or remove consumer instances to handle new or failing topics.

Consumer thread pool tuning – expose the thread pool so its core size can be adjusted when a consumer becomes CPU‑bound.

Configuration file edits – any change to producer/consumer settings causes the watcher to reload and apply the new parameters.

Dynamic adjustment diagram
Dynamic adjustment diagram

07 Application Advantages

By decoupling configuration from code, the solution offers:

Easy adaptation to multiple environments (different nameservers, topics, or broker clusters).

Seamless hot‑reloading of producer/consumer definitions.

Extensibility via SPI for custom authentication, message handling, or other cross‑cutting concerns.

Strong community backing and Java‑first API, simplifying source‑level debugging and extensions.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

BackendJavaCloud NativeMessage QueueRocketMQSPI
Alibaba Cloud Native
Written by

Alibaba Cloud Native

We publish cloud-native tech news, curate in-depth content, host regular events and live streams, and share Alibaba product and user case studies. Join us to explore and share the cloud-native insights you need.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.