Class MessageQueueFactory
- Namespace
- DotCompute.Core.Messaging
- Assembly
- DotCompute.Core.dll
Factory for creating message queue instances based on configuration options.
public static class MessageQueueFactory
- Inheritance
-
MessageQueueFactory
- Inherited Members
Remarks
Provides a centralized way to create message queues with appropriate implementations based on the configuration. Selects between lock-free ring buffer (MessageQueue<T>) and priority-based heap (PriorityMessageQueue<T>) implementations.
Methods
CreateDefault<T>()
Creates a message queue instance with default options.
public static IMessageQueue<T> CreateDefault<T>() where T : IRingKernelMessage
Returns
- IMessageQueue<T>
A message queue instance with default configuration (capacity: 1024, FIFO ordering, deduplication enabled, Block backpressure strategy).
Type Parameters
TThe message type implementing IRingKernelMessage.
Remarks
Creates a lock-free MessageQueue<T> with default settings suitable for most use cases. For custom configuration, use Create<T>(MessageQueueOptions).
CreateHighThroughput<T>(int)
Creates a high-throughput message queue optimized for performance.
public static IMessageQueue<T> CreateHighThroughput<T>(int capacity = 4096) where T : IRingKernelMessage
Parameters
capacityintThe queue capacity (must be power of 2, will be rounded up).
Returns
- IMessageQueue<T>
A lock-free message queue optimized for high throughput with minimal overhead.
Type Parameters
TThe message type implementing IRingKernelMessage.
Remarks
Creates a MessageQueue<T> with optimizations for maximum throughput:
- Deduplication disabled (no dictionary overhead)
- DropOldest backpressure (non-blocking)
- No message timeout checking
Use this for high-frequency, low-latency message passing where deduplication and message timeout are not required.
CreatePriority<T>()
Creates a priority-based message queue with default options.
public static IMessageQueue<T> CreatePriority<T>() where T : IRingKernelMessage
Returns
- IMessageQueue<T>
A priority message queue instance with default configuration (capacity: 1024, priority ordering enabled, deduplication enabled, Block backpressure strategy).
Type Parameters
TThe message type implementing IRingKernelMessage.
Remarks
Creates a PriorityMessageQueue<T> with default settings for scenarios where message priority is important. Messages are dequeued in order of highest priority first.
Create<T>(MessageQueueOptions)
Creates a message queue instance based on the provided options.
public static IMessageQueue<T> Create<T>(MessageQueueOptions options) where T : IRingKernelMessage
Parameters
optionsMessageQueueOptionsConfiguration options for the queue.
Returns
- IMessageQueue<T>
A message queue instance. Returns PriorityMessageQueue<T> if EnablePriorityQueue is true; otherwise, returns MessageQueue<T> for optimal performance.
Type Parameters
TThe message type implementing IRingKernelMessage.
Remarks
Implementation Selection: - MessageQueue<T>: Lock-free FIFO queue with atomic operations (~50ns per operation) - PriorityMessageQueue<T>: Binary heap with priority ordering (O(log n) per operation)
Usage:
var options = new MessageQueueOptions
{
Capacity = 2048,
EnablePriorityQueue = true,
BackpressureStrategy = BackpressureStrategy.DropOldest
};
using var queue = MessageQueueFactory.Create<MyMessage>(options);
Exceptions
- ArgumentNullException
Thrown when
optionsis null.- ArgumentOutOfRangeException
Thrown when options are invalid.