123 lines
4.0 KiB
C#
123 lines
4.0 KiB
C#
using System;
|
|
using Svrnty.CQRS.Events.Abstractions.Subscriptions;
|
|
|
|
namespace Svrnty.CQRS.Events.Abstractions.Streaming;
|
|
|
|
/// <summary>
|
|
/// Configuration for subscribing to events from a remote stream in another service.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// Remote streams allow a service to consume events published by another service
|
|
/// via an external message broker (RabbitMQ, Kafka, etc.).
|
|
/// </para>
|
|
/// <para>
|
|
/// <strong>Example Scenario:</strong>
|
|
/// Service A publishes "user-service.events" to RabbitMQ.
|
|
/// Service B subscribes to "user-service.events" as a remote stream.
|
|
/// </para>
|
|
/// </remarks>
|
|
public interface IRemoteStreamConfiguration
|
|
{
|
|
/// <summary>
|
|
/// Gets the name of the remote stream (typically the exchange/topic name).
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// Example: "user-service.events", "orders.events"
|
|
/// </remarks>
|
|
string StreamName { get; }
|
|
|
|
/// <summary>
|
|
/// Gets or sets the provider type for the remote stream.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// Supported values: "RabbitMQ", "Kafka", "AzureServiceBus", "AwsSns"
|
|
/// </remarks>
|
|
string ProviderType { get; set; }
|
|
|
|
/// <summary>
|
|
/// Gets or sets the connection string for the remote message broker.
|
|
/// </summary>
|
|
string ConnectionString { get; set; }
|
|
|
|
/// <summary>
|
|
/// Gets or sets the subscription mode for consuming events.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// <list type="bullet">
|
|
/// <item><term>Broadcast</term><description>Each consumer gets all events</description></item>
|
|
/// <item><term>Exclusive</term><description>Only one consumer gets each event</description></item>
|
|
/// <item><term>ConsumerGroup</term><description>Load-balanced across group members</description></item>
|
|
/// </list>
|
|
/// Default: ConsumerGroup (recommended for scalability)
|
|
/// </remarks>
|
|
SubscriptionMode Mode { get; set; }
|
|
|
|
/// <summary>
|
|
/// Gets or sets whether to automatically create the necessary topology (queues, bindings).
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// Default: true
|
|
/// Set to false if topology is managed externally.
|
|
/// </remarks>
|
|
bool AutoDeclareTopology { get; set; }
|
|
|
|
/// <summary>
|
|
/// Gets or sets the prefetch count for consumer-side buffering.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// Higher values increase throughput but use more memory.
|
|
/// Default: 10
|
|
/// </remarks>
|
|
int PrefetchCount { get; set; }
|
|
|
|
/// <summary>
|
|
/// Gets or sets the acknowledgment mode for consumed messages.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// <list type="bullet">
|
|
/// <item><term>Auto</term><description>Automatic acknowledgment after handler completion</description></item>
|
|
/// <item><term>Manual</term><description>Explicit acknowledgment required</description></item>
|
|
/// </list>
|
|
/// Default: Auto
|
|
/// </remarks>
|
|
AcknowledgmentMode AcknowledgmentMode { get; set; }
|
|
|
|
/// <summary>
|
|
/// Gets or sets the maximum number of redelivery attempts before dead-lettering.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// Default: 3
|
|
/// Set to 0 to disable dead-lettering (messages discarded on failure).
|
|
/// </remarks>
|
|
int MaxRedeliveryAttempts { get; set; }
|
|
|
|
/// <summary>
|
|
/// Validates the configuration.
|
|
/// </summary>
|
|
/// <exception cref="InvalidOperationException">Thrown if the configuration is invalid.</exception>
|
|
void Validate();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Acknowledgment mode for remote stream consumption.
|
|
/// </summary>
|
|
public enum AcknowledgmentMode
|
|
{
|
|
/// <summary>
|
|
/// Automatic acknowledgment after the event handler completes successfully.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// If the handler throws an exception, the message is nacked and requeued.
|
|
/// </remarks>
|
|
Auto,
|
|
|
|
/// <summary>
|
|
/// Manual acknowledgment required via explicit AcknowledgeAsync() call.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// Provides more control but requires explicit acknowledgment in handlers.
|
|
/// </remarks>
|
|
Manual
|
|
}
|