Kafka domain event publisher implementing IDomainEventPublisher, sibling to Svrnty.CQRS.Events.RabbitMQ. Uses Confluent.Kafka 2.6.1, targets net10.0 with C# 14. Features: - Configurable bootstrap servers, client id, idempotence, acks, retries - Security protocol + SASL config (Plaintext/SSL/SASL_SSL etc.) - Topic mapper (default lowercase event-type-name, custom func override) - IAsyncDisposable producer cleanup - Two registration overloads via AddKafkaDomainEvents Project added to solution. Builds with 0 warnings. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
73 lines
2.2 KiB
C#
73 lines
2.2 KiB
C#
namespace Svrnty.CQRS.Events.Kafka;
|
|
|
|
/// <summary>
|
|
/// Configuration options for Kafka domain event publishing.
|
|
/// </summary>
|
|
public class KafkaEventOptions
|
|
{
|
|
/// <summary>
|
|
/// Kafka bootstrap servers. Default: localhost:9092
|
|
/// </summary>
|
|
public string BootstrapServers { get; set; } = "localhost:9092";
|
|
|
|
/// <summary>
|
|
/// Prefix for Kafka topics. Default: domain
|
|
/// Events will be published to topics like {TopicPrefix}.{category}
|
|
/// </summary>
|
|
public string TopicPrefix { get; set; } = "domain";
|
|
|
|
/// <summary>
|
|
/// Client identifier for Kafka producer. Default: cqrs-events
|
|
/// </summary>
|
|
public string ClientId { get; set; } = "cqrs-events";
|
|
|
|
/// <summary>
|
|
/// Enable idempotent producer for exactly-once semantics. Default: true
|
|
/// </summary>
|
|
public bool EnableIdempotence { get; set; } = true;
|
|
|
|
/// <summary>
|
|
/// Message timeout in milliseconds. Default: 30000 (30 seconds)
|
|
/// </summary>
|
|
public int MessageTimeoutMs { get; set; } = 30000;
|
|
|
|
/// <summary>
|
|
/// Security protocol. Default: Plaintext
|
|
/// Options: Plaintext, Ssl, SaslPlaintext, SaslSsl
|
|
/// </summary>
|
|
public string SecurityProtocol { get; set; } = "Plaintext";
|
|
|
|
/// <summary>
|
|
/// SASL mechanism for authentication. Optional.
|
|
/// Options: Plain, ScramSha256, ScramSha512
|
|
/// </summary>
|
|
public string? SaslMechanism { get; set; }
|
|
|
|
/// <summary>
|
|
/// SASL username for authentication. Optional.
|
|
/// </summary>
|
|
public string? SaslUsername { get; set; }
|
|
|
|
/// <summary>
|
|
/// SASL password for authentication. Optional.
|
|
/// </summary>
|
|
public string? SaslPassword { get; set; }
|
|
|
|
/// <summary>
|
|
/// Number of acknowledgements required. Default: All (-1)
|
|
/// Options: None (0), Leader (1), All (-1)
|
|
/// </summary>
|
|
public int Acks { get; set; } = -1;
|
|
|
|
/// <summary>
|
|
/// Maximum number of retries. Default: 3
|
|
/// </summary>
|
|
public int Retries { get; set; } = 3;
|
|
|
|
/// <summary>
|
|
/// Custom topic mapping function. If not set, default mapping is used.
|
|
/// Maps event type name to topic name.
|
|
/// </summary>
|
|
public Func<string, string>? TopicMapper { get; set; }
|
|
}
|