Table of Contents

Class SpanBasedMessageRouter<TMessage>

Namespace
Excalibur.Dispatch.Routing
Assembly
Excalibur.Dispatch.dll

High-performance message router that uses Span<T> and avoids allocations. Optimized for scenarios where routing decisions must be made in microseconds.

public sealed class SpanBasedMessageRouter<TMessage> : IDisposable where TMessage : unmanaged, IRoutableMessage

Type Parameters

TMessage
Inheritance
SpanBasedMessageRouter<TMessage>
Implements
Inherited Members
Extension Methods

Constructors

SpanBasedMessageRouter(int, int)

High-performance message router that uses Span<T> and avoids allocations. Optimized for scenarios where routing decisions must be made in microseconds.

public SpanBasedMessageRouter(int maxRoutes, int cacheSize = 1024)

Parameters

maxRoutes int
cacheSize int

Methods

ClearCache()

Clears the internal routing cache to force fresh evaluation of routing decisions.

public void ClearCache()

Dispose()

Disposes the message router, releasing thread-local buffers and other resources.

public void Dispose()

FindAllRoutes(in TMessage, Span<int>)

Find all matching routes for a message (for multicast scenarios).

public int FindAllRoutes(in TMessage message, Span<int> matchingRoutes)

Parameters

message TMessage
matchingRoutes Span<int>

Returns

int

GetStatistics()

Gets comprehensive statistics about the routing performance and state.

public RouteStatistics GetStatistics()

Returns

RouteStatistics

Statistics including active routes, cache performance, and routing metrics.

RouteBatch(ReadOnlySpan<TMessage>, Span<int>)

Route multiple messages in batch with optimized memory access.

public void RouteBatch(ReadOnlySpan<TMessage> messages, Span<int> routeIds)

Parameters

messages ReadOnlySpan<TMessage>
routeIds Span<int>

RouteMessage(in TMessage)

Route a single message with minimal overhead.

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public int RouteMessage(in TMessage message)

Parameters

message TMessage

Returns

int

TryAddRoute(int, Predicate<TMessage>, int)

Add a route to the router.

public bool TryAddRoute(int routeId, Predicate<TMessage> predicate, int priority = 0)

Parameters

routeId int
predicate Predicate<TMessage>
priority int

Returns

bool