67 lines
2.2 KiB
C#
67 lines
2.2 KiB
C#
using System;
|
|
using Svrnty.CQRS.Events.Abstractions.Streaming;
|
|
using Svrnty.CQRS.Events.Abstractions.Subscriptions;
|
|
|
|
namespace Svrnty.CQRS.Events.Abstractions.Configuration;
|
|
|
|
/// <summary>
|
|
/// Default implementation of remote stream configuration.
|
|
/// </summary>
|
|
public sealed class RemoteStreamConfiguration : IRemoteStreamConfiguration
|
|
{
|
|
/// <summary>
|
|
/// Initializes a new instance of the <see cref="RemoteStreamConfiguration"/> class.
|
|
/// </summary>
|
|
/// <param name="streamName">The name of the remote stream.</param>
|
|
public RemoteStreamConfiguration(string streamName)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(streamName))
|
|
throw new ArgumentException("Stream name cannot be null or whitespace.", nameof(streamName));
|
|
|
|
StreamName = streamName;
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public string StreamName { get; }
|
|
|
|
/// <inheritdoc />
|
|
public string ProviderType { get; set; } = "RabbitMQ";
|
|
|
|
/// <inheritdoc />
|
|
public string ConnectionString { get; set; } = string.Empty;
|
|
|
|
/// <inheritdoc />
|
|
public SubscriptionMode Mode { get; set; } = SubscriptionMode.ConsumerGroup;
|
|
|
|
/// <inheritdoc />
|
|
public bool AutoDeclareTopology { get; set; } = true;
|
|
|
|
/// <inheritdoc />
|
|
public int PrefetchCount { get; set; } = 10;
|
|
|
|
/// <inheritdoc />
|
|
public AcknowledgmentMode AcknowledgmentMode { get; set; } = AcknowledgmentMode.Auto;
|
|
|
|
/// <inheritdoc />
|
|
public int MaxRedeliveryAttempts { get; set; } = 3;
|
|
|
|
/// <inheritdoc />
|
|
public void Validate()
|
|
{
|
|
if (string.IsNullOrWhiteSpace(StreamName))
|
|
throw new InvalidOperationException("StreamName cannot be null or whitespace.");
|
|
|
|
if (string.IsNullOrWhiteSpace(ProviderType))
|
|
throw new InvalidOperationException("ProviderType must be specified.");
|
|
|
|
if (string.IsNullOrWhiteSpace(ConnectionString))
|
|
throw new InvalidOperationException("ConnectionString must be specified.");
|
|
|
|
if (PrefetchCount <= 0)
|
|
throw new InvalidOperationException("PrefetchCount must be positive.");
|
|
|
|
if (MaxRedeliveryAttempts < 0)
|
|
throw new InvalidOperationException("MaxRedeliveryAttempts cannot be negative.");
|
|
}
|
|
}
|