Interface IMessageBatcher
- Namespace
- DotCompute.Abstractions.Messaging
- Assembly
- DotCompute.Abstractions.dll
Batches multiple messages together for efficient transmission and processing.
public interface IMessageBatcher : IAsyncDisposable
- Inherited Members
Remarks
Features:
- Configurable batch size limits
- Time-based batch flushing
- Memory-efficient batching with pooled buffers
- Support for heterogeneous message types
Properties
CurrentBatchSize
Gets the current number of messages in the batch.
int CurrentBatchSize { get; }
Property Value
CurrentPayloadSize
Gets the current total payload size in bytes.
long CurrentPayloadSize { get; }
Property Value
IsReadyToFlush
Gets a value indicating whether the batch is ready to flush based on configured triggers.
bool IsReadyToFlush { get; }
Property Value
Methods
AddAsync<TMessage>(TMessage, CancellationToken)
Adds a message to the current batch.
Task<bool> AddAsync<TMessage>(TMessage message, CancellationToken cancellationToken = default) where TMessage : IRingKernelMessage
Parameters
messageTMessageThe message to add.
cancellationTokenCancellationTokenCancellation token.
Returns
- Task<bool>
A task that completes when the message is added. Returns true if the batch is ready to flush after adding.
Type Parameters
TMessageThe message type.
FlushAsync(CancellationToken)
Flushes the current batch and returns the batched payload.
Task<MessageBatch> FlushAsync(CancellationToken cancellationToken = default)
Parameters
cancellationTokenCancellationTokenCancellation token.
Returns
- Task<MessageBatch>
The batched messages as a single payload.
Events
BatchFlushed
Occurs when a batch is automatically flushed due to timeout.
event EventHandler<BatchFlushedEventArgs>? BatchFlushed