This topic describes the batch consumption feature of Message Queue for Apache RocketMQ, including the feature description, scenarios, limits, and configuration method.

Feature description

After messages are received from producers, Message Queue for Apache RocketMQ can cache the messages first instead of pushing them to consumers one by one. Message Queue for Apache RocketMQ pushes the messages to consumers at a time when the specified wait time is reached or the specified number of messages are cached.

The ConsumeMessageBatchMaxSize parameter specifies the maximum number of cached messages allowed, and the BatchConsumeMaxAwaitDurationInSeconds parameter specifies the maximum time to wait. For more information about how to set these parameters, see Sample code of batch consumption in push mode.

  • ConsumeMessageBatchMaxSize: the maximum number of messages to be consumed in a batch. If the number of cached messages reaches the specified value of this parameter, Message Queue for Apache RocketMQ pushes the cached messages to consumers at a time.
  • BatchConsumeMaxAwaitDurationInSeconds: the maximum wait time for batch consumption. Message Queue for Apache RocketMQ pushes the cached messages to consumers at a time after the specified wait time.

Scenarios

If your business has higher requirements on throughput than latency of messaging, we recommend that you configure batch consumption. Assume that you want to insert data into a database. If you run an insert job for each new piece of data and need to frequently update data, the server may be under high pressure. To solve this problem, you can use the batch consumption feature of Message Queue for Apache RocketMQ. For example, you can configure this feature to insert every 10 pieces of data in a batch or run an insert job every 5 seconds. This way, the system operating pressure can be reduced.

Limits

Message Queue for Apache RocketMQ allows you to configure batch consumption only when messages are obtained in push mode.

Configuration method

For more information about how to configure batch consumption, see Sample code.

Notice To configure batch consumption in Message Queue for Apache RocketMQ, you must upgrade your TCP-based SDK for Java to version 1.8.7.2 or later. For more information about versions and access methods of SDK for Java, see Release notes of SDK for Java.