Table of Contents

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

int

CurrentPayloadSize

Gets the current total payload size in bytes.

long CurrentPayloadSize { get; }

Property Value

long

IsReadyToFlush

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

bool IsReadyToFlush { get; }

Property Value

bool

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

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.

FlushAsync(CancellationToken)

Flushes the current batch and returns the batched payload.

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.

event EventHandler<BatchFlushedEventArgs>? BatchFlushed

Event Type

EventHandler<BatchFlushedEventArgs>