| | | 1 | | namespace AsyncResponse.Transports.GooglePubSub; |
| | | 2 | | |
| | | 3 | | /// <summary> |
| | | 4 | | /// Options for the Google Pub/Sub AsyncResponse transport. |
| | | 5 | | /// </summary> |
| | | 6 | | public sealed class GooglePubSubAsyncResponseOptions |
| | | 7 | | { |
| | | 8 | | public const string TransportName = "google-pubsub"; |
| | | 9 | | |
| | | 10 | | /// <summary>Google Cloud project id containing the topics/subscriptions.</summary> |
| | | 11 | | public string? ProjectId { get; set; } |
| | | 12 | | |
| | | 13 | | /// <summary>Topic id used by <see cref="GooglePubSubWorkerTransport"/> to publish worker jobs.</summary> |
| | | 14 | | public string? WorkerTopicId { get; set; } |
| | | 15 | | |
| | | 16 | | /// <summary>Subscription id consumed by the worker subscriber hosted service.</summary> |
| | | 17 | | public string? WorkerSubscriptionId { get; set; } |
| | | 18 | | |
| | | 19 | | /// <summary> |
| | | 20 | | /// Worker subscription handling options. The default acknowledgement mode waits until the worker |
| | | 21 | | /// handler completes before ACKing; call <see cref="GooglePubSubSubscriberOptions.UseAckAfterEnqueue"/> |
| | | 22 | | /// explicitly to opt into early ACK after bounded background enqueue. |
| | | 23 | | /// </summary> |
| | | 24 | | public GooglePubSubSubscriberOptions WorkerSubscriber { get; } = new(); |
| | | 25 | | |
| | | 26 | | /// <summary> |
| | | 27 | | /// Topic id that async-response messages are published to (by the remote system or worker) and |
| | | 28 | | /// that <see cref="ResponseSubscriptionId"/> is attached to. The transport consumes responses |
| | | 29 | | /// through the subscription; it does not itself publish to this topic. |
| | | 30 | | /// </summary> |
| | | 31 | | public string? ResponseTopicId { get; set; } |
| | | 32 | | |
| | | 33 | | /// <summary>Subscription id consumed by the response-ingress hosted service.</summary> |
| | | 34 | | public string? ResponseSubscriptionId { get; set; } |
| | | 35 | | |
| | | 36 | | /// <summary> |
| | | 37 | | /// Response subscription handling options. Keep the default unless response ingress is known to be |
| | | 38 | | /// durable enough to tolerate ACKing before processing completes. |
| | | 39 | | /// </summary> |
| | | 40 | | public GooglePubSubSubscriberOptions ResponseSubscriber { get; } = new(); |
| | | 41 | | |
| | | 42 | | /// <summary>The logical reply target name used by <c>WithReplyTarget()</c>. Default: <c>default</c>.</summary> |
| | | 43 | | public string DefaultReplyTargetName { get; set; } = "default"; |
| | | 44 | | |
| | | 45 | | /// <summary> |
| | | 46 | | /// Named reply targets exposed to Core through <see cref="IAsyncResponseReplyTargetProvider"/>. |
| | | 47 | | /// When empty, <see cref="ResponseTopicId"/> becomes the default reply target. |
| | | 48 | | /// </summary> |
| | | 49 | | public Dictionary<string, GooglePubSubReplyTargetOptions> ReplyTargets { get; } = new(StringComparer.Ordinal); |
| | | 50 | | |
| | | 51 | | /// <summary> |
| | | 52 | | /// Pub/Sub message attribute that carries the AsyncResponse correlation id. Default: |
| | | 53 | | /// <c>correlationId</c>. |
| | | 54 | | /// </summary> |
| | | 55 | | public string CorrelationIdAttribute { get; set; } = "correlationId"; |
| | | 56 | | |
| | | 57 | | /// <summary> |
| | | 58 | | /// JSON paths inspected when a response message does not carry the correlation id as an |
| | | 59 | | /// attribute. Paths are case-insensitive and support nested JSON strings, such as |
| | | 60 | | /// <c>CustomParameters</c> containing serialized JSON. |
| | | 61 | | /// </summary> |
| | | 62 | | public string[] CorrelationIdJsonPaths { get; set; } = |
| | | 63 | | [ |
| | | 64 | | "CorrelationId", |
| | | 65 | | "CustomParameters", |
| | | 66 | | "CustomParameters.CorrelationId", |
| | | 67 | | "PubSubParams.CustomParameters", |
| | | 68 | | "PubSubParams.CustomParameters.CorrelationId", |
| | | 69 | | "DagJsonParameters.CorrelationId" |
| | | 70 | | ]; |
| | | 71 | | |
| | | 72 | | /// <summary>Initial delay before restarting a failed hosted subscriber.</summary> |
| | | 73 | | public TimeSpan SubscriberRetryBaseDelay { get; set; } = TimeSpan.FromMilliseconds(100); |
| | | 74 | | |
| | | 75 | | /// <summary>Maximum delay between restarts of a repeatedly failing hosted subscriber.</summary> |
| | | 76 | | public TimeSpan SubscriberRetryMaxDelay { get; set; } = TimeSpan.FromSeconds(5); |
| | | 77 | | |
| | | 78 | | /// <summary> |
| | | 79 | | /// Bounds the subscriber-client stop and publisher shutdown while hosted services stop. These |
| | | 80 | | /// complete in milliseconds when healthy; when they do not, the client is abandoned anyway, so |
| | | 81 | | /// keep this short — it counts against the host's shutdown budget. Default: <c>5s</c>. |
| | | 82 | | /// </summary> |
| | | 83 | | public TimeSpan ShutdownTimeout { get; set; } = TimeSpan.FromSeconds(5); |
| | | 84 | | |
| | | 85 | | /// <summary> |
| | | 86 | | /// The hosting shutdown budget that must contain Pub/Sub client shutdown plus |
| | | 87 | | /// <see cref="GooglePubSubSubscriberOptions.BackgroundDrainTimeout"/> when a subscriber uses |
| | | 88 | | /// <see cref="GooglePubSubAckMode.AckAfterEnqueue"/>. Defaults to the Generic Host default of |
| | | 89 | | /// 30 seconds. Set to <c>null</c> only when this budget is validated externally. |
| | | 90 | | /// </summary> |
| | | 91 | | public TimeSpan? HostShutdownTimeout { get; set; } = TimeSpan.FromSeconds(30); |
| | | 92 | | |
| | | 93 | | /// <summary>Adds or replaces a named Google Pub/Sub reply target.</summary> |
| | | 94 | | public GooglePubSubAsyncResponseOptions AddReplyTarget(string name, string projectId, string topicId) |
| | | 95 | | { |
| | | 96 | | ArgumentException.ThrowIfNullOrWhiteSpace(name); |
| | | 97 | | ArgumentException.ThrowIfNullOrWhiteSpace(projectId); |
| | | 98 | | ArgumentException.ThrowIfNullOrWhiteSpace(topicId); |
| | | 99 | | |
| | | 100 | | ReplyTargets[name] = new GooglePubSubReplyTargetOptions |
| | | 101 | | { |
| | | 102 | | ProjectId = projectId, |
| | | 103 | | TopicId = topicId |
| | | 104 | | }; |
| | | 105 | | |
| | | 106 | | return this; |
| | | 107 | | } |
| | | 108 | | } |
| | | 109 | | |
| | | 110 | | /// <summary>Options for one named Google Pub/Sub async-response reply target.</summary> |
| | | 111 | | public sealed class GooglePubSubReplyTargetOptions |
| | | 112 | | { |
| | | 113 | | /// <summary>Google Cloud project id containing the response topic. Defaults to the transport's <see cref="GooglePub |
| | | 114 | | public string? ProjectId { get; set; } |
| | | 115 | | |
| | | 116 | | /// <summary>Topic id remote systems should publish responses to.</summary> |
| | | 117 | | public string? TopicId { get; set; } |
| | | 118 | | |
| | | 119 | | /// <summary>Additional values copied to the transport-neutral reply target.</summary> |
| | 3 | 120 | | public Dictionary<string, string> Properties { get; } = new(StringComparer.Ordinal); |
| | | 121 | | } |