| | | 1 | | namespace AsyncResponse.Transports.Kafka; |
| | | 2 | | |
| | | 3 | | internal static class KafkaTransportOptionsValidator |
| | | 4 | | { |
| | | 5 | | /// <summary>Validates the supplied options.</summary> |
| | | 6 | | public static string Required(string? value, string name) |
| | 3 | 7 | | => !string.IsNullOrWhiteSpace(value) |
| | 3 | 8 | | ? value |
| | 3 | 9 | | : throw new InvalidOperationException($"{nameof(KafkaAsyncResponseTransportOptions)}.{name} must be configur |
| | | 10 | | |
| | | 11 | | /// <summary>Validates the supplied options.</summary> |
| | | 12 | | public static void Positive(TimeSpan value, string name) |
| | | 13 | | { |
| | 3 | 14 | | if (value <= TimeSpan.Zero) |
| | 3 | 15 | | throw new InvalidOperationException($"{nameof(KafkaAsyncResponseTransportOptions)}.{name} must be positive." |
| | 3 | 16 | | } |
| | | 17 | | |
| | | 18 | | /// <summary>Validates the supplied options.</summary> |
| | | 19 | | public static void ValidateCommon(KafkaAsyncResponseTransportOptions options) |
| | | 20 | | { |
| | 3 | 21 | | _ = Required(options.BootstrapServers, nameof(options.BootstrapServers)); |
| | 3 | 22 | | _ = Required(options.TopicPrefix, nameof(options.TopicPrefix)); |
| | 3 | 23 | | _ = Required(options.WorkerConsumerGroup, nameof(options.WorkerConsumerGroup)); |
| | 3 | 24 | | _ = Required(options.ResponseConsumerGroup, nameof(options.ResponseConsumerGroup)); |
| | 3 | 25 | | _ = Required(options.CorrelationIdHeader, nameof(options.CorrelationIdHeader)); |
| | 3 | 26 | | _ = Required(options.DefaultReplyTargetName, nameof(options.DefaultReplyTargetName)); |
| | | 27 | | |
| | 3 | 28 | | if (options.DeadLetterEnabled && string.IsNullOrWhiteSpace(options.DeadLetterTopic)) |
| | 3 | 29 | | _ = Required(options.DeadLetterTopicSuffix, nameof(options.DeadLetterTopicSuffix)); |
| | | 30 | | |
| | 3 | 31 | | Positive(options.OffsetCommitInterval, nameof(options.OffsetCommitInterval)); |
| | 3 | 32 | | Positive(options.OperationTimeout, nameof(options.OperationTimeout)); |
| | 3 | 33 | | Positive(options.PublishRetryBaseDelay, nameof(options.PublishRetryBaseDelay)); |
| | 3 | 34 | | Positive(options.PublishRetryMaxDelay, nameof(options.PublishRetryMaxDelay)); |
| | 3 | 35 | | Positive(options.SubscriberRetryBaseDelay, nameof(options.SubscriberRetryBaseDelay)); |
| | 3 | 36 | | Positive(options.SubscriberRetryMaxDelay, nameof(options.SubscriberRetryMaxDelay)); |
| | | 37 | | |
| | 3 | 38 | | if (options.PublishMaxAttempts <= 0) |
| | 3 | 39 | | throw new InvalidOperationException($"{nameof(KafkaAsyncResponseTransportOptions)}.{nameof(options.PublishMa |
| | | 40 | | |
| | 3 | 41 | | if (options.PublishRetryBaseDelay > options.PublishRetryMaxDelay) |
| | | 42 | | { |
| | 3 | 43 | | throw new InvalidOperationException( |
| | 3 | 44 | | $"{nameof(KafkaAsyncResponseTransportOptions)}.{nameof(options.PublishRetryBaseDelay)} cannot exceed " + |
| | 3 | 45 | | $"{nameof(KafkaAsyncResponseTransportOptions)}.{nameof(options.PublishRetryMaxDelay)}."); |
| | | 46 | | } |
| | | 47 | | |
| | 3 | 48 | | if (options.SubscriberRetryBaseDelay > options.SubscriberRetryMaxDelay) |
| | | 49 | | { |
| | 3 | 50 | | throw new InvalidOperationException( |
| | 3 | 51 | | $"{nameof(KafkaAsyncResponseTransportOptions)}.{nameof(options.SubscriberRetryBaseDelay)} cannot exceed |
| | 3 | 52 | | $"{nameof(KafkaAsyncResponseTransportOptions)}.{nameof(options.SubscriberRetryMaxDelay)}."); |
| | | 53 | | } |
| | | 54 | | |
| | 3 | 55 | | if (options.TopicNumPartitions is not -1 and <= 0) |
| | 3 | 56 | | throw new InvalidOperationException($"{nameof(KafkaAsyncResponseTransportOptions)}.{nameof(options.TopicNumP |
| | | 57 | | |
| | 3 | 58 | | if (options.TopicReplicationFactor is not (-1) and <= 0) |
| | 3 | 59 | | throw new InvalidOperationException($"{nameof(KafkaAsyncResponseTransportOptions)}.{nameof(options.TopicRepl |
| | | 60 | | |
| | 3 | 61 | | if (options.HostShutdownTimeout is { } hostShutdownTimeout && hostShutdownTimeout <= TimeSpan.Zero) |
| | 3 | 62 | | throw new InvalidOperationException($"{nameof(KafkaAsyncResponseTransportOptions)}.{nameof(options.HostShutd |
| | 3 | 63 | | } |
| | | 64 | | } |