| | | 1 | | namespace AsyncResponse.Transports.SQS; |
| | | 2 | | |
| | | 3 | | /// <summary> |
| | | 4 | | /// Interprets the queue strings accepted by <see cref="SqsAsyncResponseOptions"/>: either a plain |
| | | 5 | | /// queue name (resolved through <c>GetQueueUrl</c>) or a full queue URL. |
| | | 6 | | /// </summary> |
| | | 7 | | internal static class SqsQueueAddress |
| | | 8 | | { |
| | | 9 | | /// <summary>Returns <c>true</c> when the configured queue string is a full queue URL.</summary> |
| | | 10 | | public static bool IsUrl(string queue) |
| | 6215 | 11 | | => queue.StartsWith("http://", StringComparison.OrdinalIgnoreCase) |
| | 6215 | 12 | | || queue.StartsWith("https://", StringComparison.OrdinalIgnoreCase); |
| | | 13 | | |
| | | 14 | | /// <summary>Returns <c>true</c> when the queue (name or URL) addresses an SQS FIFO queue.</summary> |
| | | 15 | | public static bool IsFifo(string queue) |
| | 3548 | 16 | | => QueueName(queue).EndsWith(".fifo", StringComparison.OrdinalIgnoreCase); |
| | | 17 | | |
| | | 18 | | /// <summary>Extracts the queue name from a queue string (the last URL segment, or the string itself).</summary> |
| | | 19 | | public static string QueueName(string queue) |
| | | 20 | | { |
| | 3580 | 21 | | var trimmed = queue.TrimEnd('/'); |
| | 3580 | 22 | | if (!IsUrl(trimmed)) |
| | 3540 | 23 | | return trimmed; |
| | | 24 | | |
| | 40 | 25 | | var lastSegment = trimmed.LastIndexOf('/'); |
| | 40 | 26 | | return lastSegment >= 0 ? trimmed[(lastSegment + 1)..] : trimmed; |
| | | 27 | | } |
| | | 28 | | |
| | | 29 | | /// <summary> |
| | | 30 | | /// Derives the dead-letter queue name provisioning creates for <paramref name="queueName"/>: |
| | | 31 | | /// the suffix is appended, and for FIFO queues re-inserted before the mandatory |
| | | 32 | | /// <c>.fifo</c> tail (a FIFO queue's dead-letter queue must itself be FIFO). The validator |
| | | 33 | | /// uses the SAME derivation to reject collisions with a live queue, so the two must not drift. |
| | | 34 | | /// </summary> |
| | | 35 | | public static string DeriveDeadLetterQueueName(string queueName, string suffix) |
| | 2020 | 36 | | => IsFifo(queueName) |
| | 2020 | 37 | | ? $"{queueName[..^".fifo".Length]}{suffix}.fifo" |
| | 2020 | 38 | | : $"{queueName}{suffix}"; |
| | | 39 | | } |