amqpx / index / BatchConsumerOptions
Type Alias: BatchConsumerOptions<T>
BatchConsumerOptions<
T> =ConsumerOptions<T> &object
Defined in: src/consumer/types.ts:115
Type Declaration
batchFailureStrategy?
optionalbatchFailureStrategy?:BatchFailureStrategy
How to handle a batch of messages when processing fails (throws error). Options are:
- Fail: reject the whole batch; the consumer will not try to reprocess the messages.
- Split: split the batch into individual messages and try to process each one separately.
batchSize?
optionalbatchSize?:number
How many messages are in single batch. Consumer can process multiple batches in parallel, when prefetch is higher than the batch size.
The batch can be smaller, for example when not enough messages were received during maxWaitTimeForBatch, or when batchFailureStrategy is set to Split.
If not specified, prefetch size will be used as a batch size. If either batch size nor prefetch is specified, the default value is 20.
maxWaitTimeForAck?
optionalmaxWaitTimeForAck?:number
After batch is successfully processed, and failureStrategy is not set to Reject, consumer needs to confirm messages to the RabbitMQ broker. If there is different batch, that has older messages than the current one, consumer will wait some time before acknowledge the messages (so the batch with older messages have some time to finish).
Reasoning behind is that Rabbit allows to either acknowledge each message separately, or acknowledge sequential set of messages using single call (faster). When batch, that is not the oldest one, finish processing, this timeout allows it to wait for the oldest batch to complete, allowing consumer to acknowledge all the messages (both from the older batch, as well for the current) using single acknowledgement call.
When the processed job is the oldest, this property doesn't delay the acknowledgement and the consumer acknowledge the whole batch right away using single call.
If the older batches are not processed until the specified time, consumer acknowledge each message separately.
The property allows to wait for acknowledgements only, rejections are send to the RabbitMQ broker immediately and there is currently no way to control it.
This property effectively controls how long the message can wait before is acknowledge, but after it is processed by listener.
The value is specified in milliseconds. Default value is 0, meaning the consumer doesn't wait for older batches to finish processing.
maxWaitTimeForBatch?
optionalmaxWaitTimeForBatch?:number
Time in milliseconds to wait before process incomplete batch.
When consumer doesn't have enough messages in buffer, it will wait specified number of milliseconds for new messages to arrive. If after the time there is still not enough messages, the consumer will invoke the listener with smaller batch.
Effectively, this property controls for how long the message can be in buffer before the consumer invokes listener for it.
By default is 100ms.
Type Parameters
| Type Parameter |
|---|
T |