Class MessageBatcher
- Namespace
- DotCompute.Core.Messaging
- Assembly
- DotCompute.Core.dll
Batches multiple messages together for efficient transmission.
public sealed class MessageBatcher : IMessageBatcher, IAsyncDisposable
- Inheritance
-
MessageBatcher
- Implements
- Inherited Members
Constructors
MessageBatcher(BatchingOptions, ILogger<MessageBatcher>)
Creates a new message batcher with the specified options.
public MessageBatcher(BatchingOptions options, ILogger<MessageBatcher> logger)
Parameters
optionsBatchingOptionsBatching options.
loggerILogger<MessageBatcher>Logger for diagnostics.
MessageBatcher(ILogger<MessageBatcher>)
Creates a new message batcher with default options.
public MessageBatcher(ILogger<MessageBatcher> logger)
Parameters
loggerILogger<MessageBatcher>Logger for diagnostics.
Properties
CurrentBatchSize
Gets the current number of messages in the batch.
public int CurrentBatchSize { get; }
Property Value
CurrentPayloadSize
Gets the current total payload size in bytes.
public long CurrentPayloadSize { get; }
Property Value
IsReadyToFlush
Gets a value indicating whether the batch is ready to flush based on configured triggers.
public bool IsReadyToFlush { get; }
Property Value
Methods
AddAsync<TMessage>(TMessage, CancellationToken)
Adds a message to the current batch.
public 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.
DisposeAsync()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources asynchronously.
public ValueTask DisposeAsync()
Returns
- ValueTask
A task that represents the asynchronous dispose operation.
FlushAsync(CancellationToken)
Flushes the current batch and returns the batched payload.
public 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.
public event EventHandler<BatchFlushedEventArgs>? BatchFlushed