HareMq 1.5.0 Release Notes
New Features
Batch Consumer Support
Consumers can now accumulate and process multiple messages at once using two new options:
| Option | Default | Description |
|---|---|---|
batch_size |
1 |
Number of messages to accumulate before dispatching to consume/2 |
batch_timeout_ms |
5000 |
Milliseconds to wait before flushing a partial batch |
When batch_size > 1, implement consume/2 instead of consume/1:
defmodule MyApp.BatchConsumer do
use HareMq.Consumer,
queue_name: "my_queue",
batch_size: 10,
batch_timeout_ms: 2000
def consume(messages, :batch) do
IO.puts("Received batch of #{length(messages)} messages")
:ok
end
endHow it works:
- The consumer buffers incoming messages until
batch_sizemessages are received orbatch_timeout_mselapses, whichever comes first. prefetch_countis automatically set to at leastbatch_sizeto ensure the broker delivers enough messages.- Returning
:okor{:ok, _}individually acknowledges every message in the batch. - Returning
:erroror{:error, _}triggers the retry/dead-letter flow for each message independently. - Pending batch messages are nack'd if the consumer process crashes or terminates.
Feature compatibility:
Batch processing integrates with all existing HareMq features:
- Retry & Delay Cascade — Each message in a failed batch is independently routed through the retry flow with its own delay and retry count.
- Dead-lettering — Individual messages that exceed
retry_limitare moved to the.deadqueue. - Auto-scaling —
HareMq.DynamicConsumersupportsbatch_size. TheAutoScalerscales worker processes based on queue depth as usual. - Stream Queues —
batch_sizeworks withstream: truefor high-performance log processing.
Tests
- Added integration test suite
HareMq.Consumer.BatchTestcovering:- Full batch dispatch when
batch_sizeis reached. - Partial batch flush triggered by
batch_timeout_ms. - Batch processing on stream queues.
- Per-message retry republishing when a batch returns
:error. - Verification that failed batch messages appear in the delay queue.
- Full batch dispatch when
Upgrade Notes
Update your dependency in mix.exs:
{:hare_mq, "~> 1.5.0"}Existing consumers that implement consume/1 continue to work without any changes. Batch processing is opt-in via batch_size.
Full Changelog: v1.4.0...v1.5.0