Apache RocketMQ

repository·develop·Indexed 12 days ago

https://github.com/apache/rocketmq

A distributed messaging and streaming platform designed for low latency, high performance, and high reliability. It supports transactional messages and multiple protocols including gRPC, MQTT, and JMS. Key components include the NameServer, Broker, and the RocketMQ Proxy for stateless consumption and protocol translation. Version 5.0 introduces POP consumption, automatic master-slave switchover, and gRPC Proxy support.

Tokens
168.7K
Snippets
474
Records
718
Agent score
94%

What's inside RocketMQ

  1. Introduction to RocketMQ Proxy

    develop

    RocketMQ Proxy is a stateless component designed to enable stateless consumption behavior by leveraging the pop consumption mechanism. It acts as a traffic interface that translates incoming traffic (such as gRPC) into the customized Remoting protocol used to communicate with Broker and Namesrv.

    Key responsibilities of the Proxy include:

    • Protocol Translation: Converting external protocols to internal Remoting protocol.
    • Security: Handling SSL, authorization, and authentication.
    • Observability: Managing logging, tracing, and metrics.
    • Traffic Management: Handling connection management and traffic governance.
    • Message Support: Supports normal, fifo, transaction, and delay message types via pop consumption mode.
  2. Explore Apache RocketMQ Concepts and Features

    develop
    To understand the fundamental building blocks and functional capabilities of Apache RocketMQ, refer to the dedicated Concept and Feature documentation. These resources cover basic terminology and the specific functional implementations available in the RocketMQ ecosystem.
  3. Explore RocketMQ 5.0 New Features

    develop

    RocketMQ 5.0 introduces several advanced features:

    • POP Consumption: Server-side rebalance and lightweight consumer client support.
    • StaticTopic: Logic queue design for static topics.
    • BatchConsumeQueue: Improved throughput for batch message processing.
    • Automatic Master-Slave Switchover: Enhanced high availability.
    • BrokerContainer: Containerized broker capabilities.
    • SlaveActingMasterMode: A specific mode for slave nodes.
    • gRPC Proxy: Support for gRPC-based proxy communication.
  4. Explore RocketMQ Concepts and Features

    develop

    To understand the fundamental model and capabilities of Apache RocketMQ, refer to the following documentation:

    • Concepts: Learn about the basic conceptual models used by RocketMQ.
    • Features: Understand the functional capabilities and features implemented by RocketMQ.
  5. What is Light Message Queue (LMQ)?

    develop

    Light Message Queue (LMQ) uses a read-amplification strategy to optimize storage and performance. Instead of writing multiple copies of a message for different consumption scenarios, a single message is written to the commitlog. The broker then dispatches multiple ConsumerQueue indices based on different requirements.

    This allows a single message to support:

    1. Server-side scenarios (MQ/AMQP): Traditional consumption based on top-level Topic queues.
    2. Client-side scenarios (MQTT): Consumption based on multi-level MQTT topics (LMQ).
  6. What is a RocketMQ-on-DLedger Group

    develop

    A RocketMQ-on-DLedger Group is a broker group designed for high availability using the Raft algorithm.

    Key characteristics:

    • Automatic Failover: The group automatically elects a Leader via Raft; other nodes act as Followers.
    • Data Consistency: The Leader replicates data to Followers to maintain system consistency.
    • Node Requirements: A group requires at least 3 nodes to tolerate one node failure. While 2 nodes can be deployed, they lack failover capabilities.
    • Scaling: You can scale horizontally by deploying multiple independent DLedger Groups to provide external services.
  7. What is BrokerContainer and how does it work?

    develop

    In RocketMQ 5.x, BrokerContainer is a new deployment mode that allows multiple independent Brokers (Master, Slave, or DLedger) to run within a single process.

    Key Concepts

    • Resource Efficiency: Multiple brokers share the same process, improving single-node resource utilization.
    • Shared Transport Layer: All brokers within a BrokerContainer share the same underlying transport layer (Netty instance, computing resources, and protocol stack), though each broker maintains its own port and ProcessorTable.
    • High Availability: Enables "Peer Deployment" patterns (e.g., 2-replica or 3-replica configurations) where nodes are cross-deployed so that if one physical node fails, the remaining nodes contain both master and slave brokers, ensuring continuous message availability.
    • Isolation: Each broker within the container has its own isolated CommitLog.
  8. What is RocketMQ-on-DLedger Group

    develop

    A RocketMQ-on-DLedger Group is a high-availability deployment pattern using the Raft consensus algorithm. It consists of a group of Brokers with the same name (at least 3 nodes).

    Key characteristics:

    • Automatic Failover: Raft automatically elects a Leader; other nodes act as Followers.
    • Data Consistency: Data is replicated between the Leader and Followers to ensure high availability and consistency.
    • Scalability: You can deploy multiple independent DLedger Groups to scale horizontally.
  9. Implement Message Ordering in RocketMQ

    develop

    RocketMQ provides two types of message ordering to ensure messages are consumed in the order they were published:

    1. Global Message Ordering: All messages within a specific Topic are published and consumed in strict First-In-First-Out (FIFO) order. Use this when performance requirements are low and strict global sequence is mandatory.
    2. Partitioned Message Ordering: Messages within a Topic are partitioned using a sharding key. Messages sharing the same sharding key are sent to the same partition and consumed in strict FIFO order. This allows for high-performance parallel consumption across different partitions while maintaining order for specific groups (e.g., all messages for a specific orderId).
  10. DLedgerController core design and roles

    develop

    The DLedgerController ensures metadata consistency using the Raft protocol. It operates in two roles:

    1. Active DLedgerController (Leader): The elected leader that accepts event requests from clients, initiates consensus through DLedger, and applies changes to an in-memory metadata state machine.
    2. Not Active DLedgerController (Follower): Replicates event logs from the Active controller via DLedger and applies them to its own state machine.
  11. How DefaultMQPullConsumer works

    develop

    The DefaultMQPullConsumer (implementing MQPullConsumer) is a consumer that actively pulls messages from Brokers. Unlike push consumers, the application controls the pulling process, allowing for batch consumption and manual control over the consumption flow.

    Key Characteristics

    • Control: The consumer decides when and how much to pull, making it ideal for scenarios where the consumer needs to manage its own processing capacity (e.g., slow consumers).
    • Workflow: To use it, you must manually:
      1. Fetch the set of MessageQueues for a specific Topic.
      2. Iterate through the MessageQueues.
      3. Pull messages from each queue (e.g., using pullBlockIfNotFound).
      4. Manage and update the consumption offset.
    • Pros: Allows for on-demand consumption and handles uneven message arrival rates well without overwhelming the consumer.
    • Cons: The consumer may not receive the latest messages immediately because it is not being 'pushed' by the broker; it is best suited for non-real-time batch processing.
    DefaultMQPullConsumer consumer = new DefaultMQPullConsumer("groupName");
  12. Enable consumption from Slave Brokers

    develop

    To reduce IO load on a Master Broker (especially when a consumer needs to reset offsets to a significant time in the past), you can enable consumption from Slave Brokers.

    Conditions for recommendation: When slaveReadEnable=true is set, the Master Broker will recommend consuming from a Slave Broker if the consumer's offset exceeds the accessMessageInMemoryMaxRatio (default is 40%).