| | | 1 | | namespace AsyncResponse.Transports.Kafka; |
| | | 2 | | |
| | | 3 | | /// <summary> |
| | | 4 | | /// Resolves Kafka topic names from transport options. These names are deployment contracts: |
| | | 5 | | /// changing them while messages are in flight strands unprocessed worker or response messages in |
| | | 6 | | /// the old topic. |
| | | 7 | | /// </summary> |
| | 3 | 8 | | internal sealed class KafkaTransportTopicSchema(KafkaAsyncResponseTransportOptions _options) |
| | | 9 | | { |
| | 3 | 10 | | public string WorkerTopic => Resolve(_options.WorkerTopic, "worker"); |
| | 3 | 11 | | public string ResponseTopic => Resolve(_options.ResponseTopic, "response"); |
| | | 12 | | |
| | | 13 | | /// <summary> |
| | | 14 | | /// The dead-letter topic for one source topic: the explicit <see cref="KafkaAsyncResponseTransportOptions.DeadLette |
| | | 15 | | /// when configured, otherwise <c>{sourceTopic}{DeadLetterTopicSuffix}</c>. |
| | | 16 | | /// </summary> |
| | | 17 | | public string DeadLetterTopicFor(string sourceTopic) |
| | 3 | 18 | | => !string.IsNullOrWhiteSpace(_options.DeadLetterTopic) |
| | 3 | 19 | | ? _options.DeadLetterTopic! |
| | 3 | 20 | | : sourceTopic + _options.DeadLetterTopicSuffix; |
| | | 21 | | |
| | | 22 | | private string Resolve(string? configured, string role) |
| | 3 | 23 | | => !string.IsNullOrWhiteSpace(configured) |
| | 3 | 24 | | ? configured! |
| | 3 | 25 | | : $"{_options.TopicPrefix}.transport.{role}"; |
| | | 26 | | } |