diff --git a/samples/persistent-subscriptions/Program.cs b/samples/persistent-subscriptions/Program.cs
index ac503f766..5390d7f23 100644
--- a/samples/persistent-subscriptions/Program.cs
+++ b/samples/persistent-subscriptions/Program.cs
@@ -37,11 +37,12 @@ class Program
static async Task ConnectToPersistentSubscriptionToStream(EventStorePersistentSubscriptionsClient client) {
#region subscribe-to-persistent-subscription-to-stream
- var subscription = await client.SubscribeAsync(
+ var subscription = await client.SubscribeToStreamAsync(
"test-stream",
"subscription-group",
async (subscription, evnt, retryCount, cancellationToken) => {
await HandleEvent(evnt);
+ await subscription.Ack(evnt);
}, (subscription, dropReason, exception) => {
Console.WriteLine($"Subscription was dropped due to {dropReason}. {exception}");
});
@@ -82,7 +83,7 @@ class Program
static async Task ConnectToPersistentSubscriptionWithManualAcks(EventStorePersistentSubscriptionsClient client) {
#region subscribe-to-persistent-subscription-with-manual-acks
- var subscription = await client.SubscribeAsync(
+ var subscription = await client.SubscribeToStreamAsync(
"test-stream",
"subscription-group",
async (subscription, evnt, retryCount, cancellationToken) => {
@@ -94,7 +95,7 @@ class Program
}
}, (subscription, dropReason, exception) => {
Console.WriteLine($"Subscription was dropped due to {dropReason}. {exception}");
- }, autoAck: false);
+ });
#endregion subscribe-to-persistent-subscription-with-manual-acks
}
diff --git a/src/EventStore.Client.PersistentSubscriptions/EventStorePersistentSubscriptionsClient.Read.cs b/src/EventStore.Client.PersistentSubscriptions/EventStorePersistentSubscriptionsClient.Read.cs
index 76afaeef0..8fdb02bd8 100644
--- a/src/EventStore.Client.PersistentSubscriptions/EventStorePersistentSubscriptionsClient.Read.cs
+++ b/src/EventStore.Client.PersistentSubscriptions/EventStorePersistentSubscriptionsClient.Read.cs
@@ -21,11 +21,40 @@ partial class EventStorePersistentSubscriptionsClient {
///
///
///
+ [Obsolete("SubscribeAsync is no longer supported. Use SubscribeToStreamAsync with manual acks instead.", true)]
public async Task SubscribeAsync(string streamName, string groupName,
Func eventAppeared,
Action? subscriptionDropped = null,
UserCredentials? userCredentials = null, int bufferSize = 10, bool autoAck = true,
CancellationToken cancellationToken = default) {
+ if (autoAck) {
+ throw new InvalidOperationException(
+ $"AutoAck is no longer supported. Please use {nameof(SubscribeToStreamAsync)} with manual acks instead.");
+ }
+
+ return await SubscribeToStreamAsync(streamName, groupName, eventAppeared, subscriptionDropped, userCredentials,
+ bufferSize, cancellationToken).ConfigureAwait(false);
+ }
+
+ ///
+ /// Subscribes to a persistent subscription. Messages must be manually acknowledged
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ public async Task SubscribeToStreamAsync(string streamName, string groupName,
+ Func eventAppeared,
+ Action? subscriptionDropped = null,
+ UserCredentials? userCredentials = null, int bufferSize = 10,
+ CancellationToken cancellationToken = default) {
if (streamName == null) {
throw new ArgumentNullException(nameof(streamName));
}
@@ -69,34 +98,32 @@ partial class EventStorePersistentSubscriptionsClient {
readOptions.StreamIdentifier = streamName;
}
- return await PersistentSubscription.Confirm(call, readOptions, autoAck, eventAppeared,
+ return await PersistentSubscription.Confirm(call, readOptions, eventAppeared,
subscriptionDropped ?? delegate { }, cancellationToken).ConfigureAwait(false);
}
///
- /// Subscribes to a persistent subscription to $all.
+ /// Subscribes to a persistent subscription to $all. Messages must be manually acknowledged
///
///
///
///
///
///
- ///
///
///
public async Task SubscribeToAllAsync(string groupName,
Func eventAppeared,
Action? subscriptionDropped = null,
- UserCredentials? userCredentials = null, int bufferSize = 10, bool autoAck = true,
+ UserCredentials? userCredentials = null, int bufferSize = 10,
CancellationToken cancellationToken = default) =>
- await SubscribeAsync(
+ await SubscribeToStreamAsync(
streamName: SystemStreams.AllStream,
groupName: groupName,
eventAppeared: eventAppeared,
subscriptionDropped: subscriptionDropped,
userCredentials: userCredentials,
bufferSize: bufferSize,
- autoAck: autoAck,
cancellationToken: cancellationToken)
.ConfigureAwait(false);
}
diff --git a/src/EventStore.Client.PersistentSubscriptions/PersistentSubscription.cs b/src/EventStore.Client.PersistentSubscriptions/PersistentSubscription.cs
index d5f910e73..00b875696 100644
--- a/src/EventStore.Client.PersistentSubscriptions/PersistentSubscription.cs
+++ b/src/EventStore.Client.PersistentSubscriptions/PersistentSubscription.cs
@@ -12,7 +12,6 @@ namespace EventStore.Client {
/// Represents a persistent subscription connection.
///
public class PersistentSubscription : IDisposable {
- private readonly bool _autoAck;
private readonly Func _eventAppeared;
private readonly Action _subscriptionDropped;
private readonly CancellationTokenSource _disposed;
@@ -25,7 +24,7 @@ public class PersistentSubscription : IDisposable {
public string SubscriptionId { get; }
internal static async Task Confirm(AsyncDuplexStreamingCall call,
- ReadReq.Types.Options options, bool autoAck,
+ ReadReq.Types.Options options,
Func eventAppeared,
Action subscriptionDropped,
CancellationToken cancellationToken = default) {
@@ -38,16 +37,14 @@ public class PersistentSubscription : IDisposable {
throw new InvalidOperationException();
}
- return new PersistentSubscription(call, autoAck, eventAppeared, subscriptionDropped);
+ return new PersistentSubscription(call, eventAppeared, subscriptionDropped);
}
private PersistentSubscription(
AsyncDuplexStreamingCall call,
- bool autoAck,
Func eventAppeared,
Action subscriptionDropped) {
_call = call;
- _autoAck = autoAck;
_eventAppeared = eventAppeared;
_subscriptionDropped = subscriptionDropped;
_disposed = new CancellationTokenSource();
@@ -146,10 +143,6 @@ public class PersistentSubscription : IDisposable {
ReadResp.Types.ReadEvent.CountOneofCase.RetryCount => current.Event.RetryCount,
_ => default
}, _disposed.Token).ConfigureAwait(false);
- if (_autoAck) {
- await AckInternal(Uuid.FromDto(current.Event.Link?.Id ?? current.Event.Event.Id))
- .ConfigureAwait(false);
- }
} catch (Exception ex) when (ex is ObjectDisposedException ||
ex is OperationCanceledException) {
SubscriptionDropped(SubscriptionDroppedReason.Disposed);
diff --git a/test/EventStore.Client.PersistentSubscriptions.Tests/Bugs/Issue_1125.cs b/test/EventStore.Client.PersistentSubscriptions.Tests/Bugs/Issue_1125.cs
index 7c14344fa..34a13144f 100644
--- a/test/EventStore.Client.PersistentSubscriptions.Tests/Bugs/Issue_1125.cs
+++ b/test/EventStore.Client.PersistentSubscriptions.Tests/Bugs/Issue_1125.cs
@@ -46,7 +46,7 @@ public static IEnumerable