Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed a GCP Pub/Sub ack batched message bug #1121

Merged
merged 3 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Microsoft.Extensions.Logging;
using Wolverine.Runtime;
using Wolverine.Transports;
using Wolverine.Util.Dataflow;

namespace Wolverine.Pubsub.Internal;

Expand Down Expand Up @@ -37,10 +38,10 @@ await streamingPull.WriteAsync(new StreamingPullRequest

await using var stream = streamingPull.GetResponseStream();

_acknowledge = ackIds => streamingPull.WriteAsync(new StreamingPullRequest
_acknowledge = new RetryBlock<string[]>((ackIds, _) => streamingPull.WriteAsync(new StreamingPullRequest
{
AckIds = { ackIds }
});
}), _logger, _runtime.Cancellation);

try
{
Expand Down
17 changes: 7 additions & 10 deletions src/Transports/GCP/Wolverine.Pubsub/Internal/PubsubListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public abstract class PubsubListener : IListener, ISupportDeadLetterQueue
protected readonly IWolverineRuntime _runtime;
protected readonly PubsubTransport _transport;

protected Func<string[], Task> _acknowledge;
protected RetryBlock<string[]> _acknowledge;
protected Task _task;

public PubsubListener(
Expand Down Expand Up @@ -51,7 +51,7 @@ IWolverineRuntime runtime
NativeDeadLetterQueueEnabled = true;
}

_acknowledge = async ackIds =>
_acknowledge = new RetryBlock<string[]>(async (ackIds, _) =>
{
if (transport.SubscriberApiClient is null)
{
Expand All @@ -65,7 +65,7 @@ await transport.SubscriberApiClient.AcknowledgeAsync(
ackIds
);
}
};
}, _logger, runtime.Cancellation);

_deadLetter = new RetryBlock<Envelope>(async (e, _) =>
{
Expand All @@ -76,7 +76,7 @@ await transport.SubscriberApiClient.AcknowledgeAsync(

if (e is PubsubEnvelope pubsubEnvelope)
{
await _acknowledge([pubsubEnvelope.AckId]);
await _acknowledge.PostAsync([pubsubEnvelope.AckId]);
}

await _deadLetterTopic.SendMessageAsync(e, _logger);
Expand All @@ -86,7 +86,7 @@ await transport.SubscriberApiClient.AcknowledgeAsync(
{
if (e is PubsubEnvelope pubsubEnvelope)
{
await _acknowledge([pubsubEnvelope.AckId]);
await _acknowledge.PostAsync([pubsubEnvelope.AckId]);
}

await _endpoint.SendMessageAsync(e, _logger);
Expand All @@ -112,10 +112,7 @@ await transport.SubscriberApiClient.AcknowledgeAsync(
.Distinct()
.ToArray();

if (ackIds.Any())
{
await _acknowledge(ackIds);
}
await _acknowledge.PostAsync(ackIds);
}, _logger, _cancellation.Token);

_task = StartAsync();
Expand Down Expand Up @@ -245,7 +242,7 @@ protected async Task handleMessagesAsync(RepeatedField<ReceivedMessage> messages
await _receiver.ReceivedAsync(this, batched);
}

await _complete.PostAsync([new Envelope(message.AckId)]);
await _acknowledge.PostAsync([message.AckId]);

continue;
}
Expand Down
Loading