View Source ExRocketmq.Consumer.BalanceStrategy.Average (lib_oss v0.1.0)

This module implements the balance strategy for RocketMQ consumers.

This strategy is called 'Average', which allocates the message queues (mq) evenly among the clients (cid). The principle of this Average implementation is as follows:

  • Sort mqs and cid_all.
  • Divide mqs into len(cid_all) parts.
  • Allocate the corresponding chunk based on the position of cid in cid_all.

Usage

  1. Create a new instance of the strategy using new/0 function.
  2. Call the allocate/4 function to allocate message queues to a specific client.

Example

strategy = Average.new()
mq_all = [mq1, mq2, mq3, mq4]
cid_all = ["client1", "client2", "client3"]
{:ok, allocated_mqs} = Average.allocate(strategy, "client2", mq_all, cid_all)

Summary

Functions