| | | 1 | | namespace AsyncResponse.Transports.Redis; |
| | | 2 | | |
| | | 3 | | internal static class RedisTransportOptionsValidator |
| | | 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(RedisAsyncResponseTransportOptions)}.{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(RedisAsyncResponseTransportOptions)}.{name} must be positive." |
| | 3 | 16 | | } |
| | | 17 | | |
| | | 18 | | /// <summary>Validates the supplied options.</summary> |
| | | 19 | | public static void PositiveOrNull(long? value, string name) |
| | | 20 | | { |
| | 3 | 21 | | if (value is <= 0) |
| | 3 | 22 | | throw new InvalidOperationException($"{nameof(RedisAsyncResponseTransportOptions)}.{name} must be positive w |
| | 3 | 23 | | } |
| | | 24 | | |
| | | 25 | | /// <summary>Validates the supplied options.</summary> |
| | | 26 | | public static void ValidateCommon(RedisAsyncResponseTransportOptions options) |
| | | 27 | | { |
| | 3 | 28 | | _ = Required(options.KeyPrefix, nameof(options.KeyPrefix)); |
| | 3 | 29 | | _ = Required(options.WorkerConsumerGroup, nameof(options.WorkerConsumerGroup)); |
| | 3 | 30 | | _ = Required(options.ResponseConsumerGroup, nameof(options.ResponseConsumerGroup)); |
| | 3 | 31 | | _ = Required(options.CorrelationIdField, nameof(options.CorrelationIdField)); |
| | 3 | 32 | | _ = Required(options.PayloadField, nameof(options.PayloadField)); |
| | 3 | 33 | | _ = Required(options.DefaultReplyTargetName, nameof(options.DefaultReplyTargetName)); |
| | | 34 | | |
| | 3 | 35 | | Positive(options.OperationTimeout, nameof(options.OperationTimeout)); |
| | 3 | 36 | | Positive(options.PublishRetryBaseDelay, nameof(options.PublishRetryBaseDelay)); |
| | 3 | 37 | | Positive(options.PublishRetryMaxDelay, nameof(options.PublishRetryMaxDelay)); |
| | 3 | 38 | | Positive(options.SubscriberRetryBaseDelay, nameof(options.SubscriberRetryBaseDelay)); |
| | 3 | 39 | | Positive(options.SubscriberRetryMaxDelay, nameof(options.SubscriberRetryMaxDelay)); |
| | 3 | 40 | | PositiveOrNull(options.StreamMaxLength, nameof(options.StreamMaxLength)); |
| | 3 | 41 | | PositiveOrNull(options.DeadLetterStreamMaxLength, nameof(options.DeadLetterStreamMaxLength)); |
| | | 42 | | |
| | 3 | 43 | | if (options.PublishMaxAttempts <= 0) |
| | 3 | 44 | | throw new InvalidOperationException($"{nameof(RedisAsyncResponseTransportOptions)}.{nameof(options.PublishMa |
| | | 45 | | |
| | 3 | 46 | | if (options.PublishRetryBaseDelay > options.PublishRetryMaxDelay) |
| | | 47 | | { |
| | 3 | 48 | | throw new InvalidOperationException( |
| | 3 | 49 | | $"{nameof(RedisAsyncResponseTransportOptions)}.{nameof(options.PublishRetryBaseDelay)} cannot exceed " + |
| | 3 | 50 | | $"{nameof(RedisAsyncResponseTransportOptions)}.{nameof(options.PublishRetryMaxDelay)}."); |
| | | 51 | | } |
| | | 52 | | |
| | 3 | 53 | | if (options.SubscriberRetryBaseDelay > options.SubscriberRetryMaxDelay) |
| | | 54 | | { |
| | 3 | 55 | | throw new InvalidOperationException( |
| | 3 | 56 | | $"{nameof(RedisAsyncResponseTransportOptions)}.{nameof(options.SubscriberRetryBaseDelay)} cannot exceed |
| | 3 | 57 | | $"{nameof(RedisAsyncResponseTransportOptions)}.{nameof(options.SubscriberRetryMaxDelay)}."); |
| | | 58 | | } |
| | | 59 | | |
| | 3 | 60 | | if (options.HostShutdownTimeout is { } hostShutdownTimeout && hostShutdownTimeout <= TimeSpan.Zero) |
| | 3 | 61 | | throw new InvalidOperationException($"{nameof(RedisAsyncResponseTransportOptions)}.{nameof(options.HostShutd |
| | 3 | 62 | | } |
| | | 63 | | } |