57 lines
1.7 KiB
C#
57 lines
1.7 KiB
C#
using System;
|
|
|
|
namespace Svrnty.CQRS.Events.Abstractions.Configuration;
|
|
|
|
/// <summary>
|
|
/// Configuration for dead letter queue behavior.
|
|
/// </summary>
|
|
public class DeadLetterQueueConfiguration
|
|
{
|
|
/// <summary>
|
|
/// Gets or sets whether DLQ is enabled for this stream.
|
|
/// </summary>
|
|
public bool Enabled { get; set; }
|
|
|
|
/// <summary>
|
|
/// Gets or sets the name of the dead letter stream.
|
|
/// If not specified, defaults to {StreamName}-dlq.
|
|
/// </summary>
|
|
public string? DeadLetterStreamName { get; set; }
|
|
|
|
/// <summary>
|
|
/// Gets or sets the maximum number of delivery attempts before sending to DLQ.
|
|
/// </summary>
|
|
public int MaxDeliveryAttempts { get; set; } = 3;
|
|
|
|
/// <summary>
|
|
/// Gets or sets the delay between retry attempts.
|
|
/// </summary>
|
|
public TimeSpan? RetryDelay { get; set; }
|
|
|
|
/// <summary>
|
|
/// Gets or sets whether to store the original event in the DLQ.
|
|
/// </summary>
|
|
public bool? StoreOriginalEvent { get; set; }
|
|
|
|
/// <summary>
|
|
/// Gets or sets whether to store error details in the DLQ.
|
|
/// </summary>
|
|
public bool? StoreErrorDetails { get; set; }
|
|
|
|
/// <summary>
|
|
/// Validates the DLQ configuration.
|
|
/// </summary>
|
|
/// <exception cref="ArgumentException">Thrown when configuration is invalid.</exception>
|
|
public void Validate()
|
|
{
|
|
if (Enabled)
|
|
{
|
|
if (MaxDeliveryAttempts <= 0)
|
|
throw new ArgumentException("MaxDeliveryAttempts must be positive", nameof(MaxDeliveryAttempts));
|
|
|
|
if (RetryDelay.HasValue && RetryDelay.Value < TimeSpan.Zero)
|
|
throw new ArgumentException("RetryDelay cannot be negative", nameof(RetryDelay));
|
|
}
|
|
}
|
|
}
|