Table of Contents

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

options BatchingOptions

Batching options.

logger ILogger<MessageBatcher>

Logger for diagnostics.

MessageBatcher(ILogger<MessageBatcher>)

Creates a new message batcher with default options.

public MessageBatcher(ILogger<MessageBatcher> logger)

Parameters

logger ILogger<MessageBatcher>

Logger for diagnostics.

Properties

CurrentBatchSize

Gets the current number of messages in the batch.

public int CurrentBatchSize { get; }

Property Value

int

CurrentPayloadSize

Gets the current total payload size in bytes.

public long CurrentPayloadSize { get; }

Property Value

long

IsReadyToFlush

Gets a value indicating whether the batch is ready to flush based on configured triggers.

public bool IsReadyToFlush { get; }

Property Value

bool

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

message TMessage

The message to add.

cancellationToken CancellationToken

Cancellation 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

TMessage

The 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

cancellationToken CancellationToken

Cancellation 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

Event Type

EventHandler<BatchFlushedEventArgs>