| | | 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) |
| | 3 | 11 | | => queue.StartsWith("http://", StringComparison.OrdinalIgnoreCase) |
| | 3 | 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) |
| | 3 | 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 | | { |
| | 3 | 21 | | var trimmed = queue.TrimEnd('/'); |
| | 3 | 22 | | if (!IsUrl(trimmed)) |
| | 3 | 23 | | return trimmed; |
| | | 24 | | |
| | 2 | 25 | | var lastSegment = trimmed.LastIndexOf('/'); |
| | 2 | 26 | | return lastSegment >= 0 ? trimmed[(lastSegment + 1)..] : trimmed; |
| | | 27 | | } |
| | | 28 | | } |