-
Notifications
You must be signed in to change notification settings - Fork 362
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: exactly once delivery (feature complete)
- Loading branch information
Showing
7 changed files
with
571 additions
and
71 deletions.
There are no files selected for viewing
251 changes: 227 additions & 24 deletions
251
apis/Google.Cloud.PubSub.V1/Google.Cloud.PubSub.V1.Tests/SubscriberClientTest.cs
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
apis/Google.Cloud.PubSub.V1/Google.Cloud.PubSub.V1/AckNackResponse.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// Copyright 2022 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"). | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
using System.Collections.Generic; | ||
|
||
namespace Google.Cloud.PubSub.V1; | ||
|
||
/// <summary> | ||
/// A public representation of a response to an ACKnowledge (ACK) or Not ACKnowledge (NACK) request. | ||
/// </summary> | ||
public sealed class AckNackResponse | ||
{ | ||
/// <summary> | ||
/// The ID of the message being ACK-ed or NACK-ed. | ||
/// </summary> | ||
public string MessageId { get; } | ||
|
||
/// <summary> | ||
/// The status of the ACK/NACK response. | ||
/// </summary> | ||
public AcknowledgementStatus Status { get; } | ||
|
||
/// <summary> | ||
/// The failure message, if any. This will be null if the response is successful. | ||
/// </summary> | ||
public string FailureMessage { get; } | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="AckNackResponse"/> class. | ||
/// </summary> | ||
/// <param name="messageId">The ID of the message being ACK-ed/NACK-ed.</param> | ||
/// <param name="status">The status of ACK/NACK response.</param> | ||
/// <param name="failureMessage">The failure message. This can be null if ACK/NACK is successful.</param> | ||
public AckNackResponse(string messageId, AcknowledgementStatus status, string failureMessage) | ||
{ | ||
MessageId = messageId; | ||
Status = status; | ||
FailureMessage = failureMessage; | ||
} | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="AckNackResponse"/> class from the pair of message ID and its corresponding permanent failure. | ||
/// </summary> | ||
/// <param name="idPermanentErrorPair">The <see cref="KeyValuePair{TKey, TValue}"/> of message ID as key and permanent error message as value.</param> | ||
/// <returns>A new instance of the <see cref="AckNackResponse"/>.</returns> | ||
internal static AckNackResponse FromIdPermanentErrorPair(KeyValuePair<string, string> idPermanentErrorPair) | ||
{ | ||
var acknowledgementException = AcknowledgementException.FromIdPermanentErrorPair(idPermanentErrorPair); | ||
return new AckNackResponse(idPermanentErrorPair.Key, acknowledgementException.Status, acknowledgementException.Message); | ||
} | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="AckNackResponse"/> class from the message ID that is successfully ACK-ed/NACK-ed. | ||
/// </summary> | ||
/// <param name="successfulId">The successful message ID.</param> | ||
/// <returns>A new instance of the <see cref="AckNackResponse"/>.</returns> | ||
internal static AckNackResponse FromSuccessfulId(string successfulId) => | ||
new AckNackResponse(successfulId, AcknowledgementStatus.Success, default); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
apis/Google.Cloud.PubSub.V1/Google.Cloud.PubSub.V1/SimpleSubscriptionHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Copyright 2022 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"). | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using static Google.Cloud.PubSub.V1.SubscriberClient; | ||
|
||
namespace Google.Cloud.PubSub.V1; | ||
|
||
/// <summary> | ||
/// This class is a simple implementation of <see cref="SubscriptionHandler"/> using a delegate. | ||
/// This is present to provide compatibility with the older <see cref="SubscriberClient.StartAsync(Func{PubsubMessage, CancellationToken, Task{Reply}})"/> implementation. | ||
/// </summary> | ||
internal sealed class SimpleSubscriptionHandler : SubscriptionHandler | ||
{ | ||
private readonly Func<PubsubMessage, CancellationToken, Task<Reply>> _handler; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="SimpleSubscriptionHandler"/> class. | ||
/// </summary> | ||
/// <param name="handler">The handler delegate that is passed all the received messages.</param> | ||
internal SimpleSubscriptionHandler(Func<PubsubMessage, CancellationToken, Task<Reply>> handler) => | ||
_handler = handler; | ||
|
||
/// <inheritdoc/> | ||
public override Task<Reply> HandleMessage(PubsubMessage message, CancellationToken cancellationToken) => | ||
_handler(message, cancellationToken); | ||
} |
Oops, something went wrong.