public async Task <PersistentSubscription> SubscribeAsync(string streamName, string groupName, Func <PersistentSubscription, ResolvedEvent, int?, CancellationToken, Task> eventAppeared, Action <PersistentSubscription, SubscriptionDroppedReason, Exception?>?subscriptionDropped = null, UserCredentials?userCredentials = null, int bufferSize = 10, bool autoAck = true, CancellationToken cancellationToken = default) { if (streamName == null) { throw new ArgumentNullException(nameof(streamName)); } if (groupName == null) { throw new ArgumentNullException(nameof(groupName)); } if (eventAppeared == null) { throw new ArgumentNullException(nameof(eventAppeared)); } if (streamName == string.Empty) { throw new ArgumentException($"{nameof(streamName)} may not be empty.", nameof(streamName)); } if (groupName == string.Empty) { throw new ArgumentException($"{nameof(groupName)} may not be empty.", nameof(groupName)); } if (bufferSize <= 0) { throw new ArgumentOutOfRangeException(nameof(bufferSize)); } var operationOptions = Settings.OperationOptions.Clone(); operationOptions.TimeoutAfter = new TimeSpan?(); var call = new PersistentSubscriptions.PersistentSubscriptions.PersistentSubscriptionsClient( await SelectCallInvoker(cancellationToken).ConfigureAwait(false)).Read(EventStoreCallOptions.Create( Settings, operationOptions, userCredentials, cancellationToken)); return(await PersistentSubscription.Confirm(call, new ReadReq.Types.Options { BufferSize = bufferSize, GroupName = groupName, StreamIdentifier = streamName, UuidOption = new ReadReq.Types.Options.Types.UUIDOption { Structured = new Empty() } }, autoAck, eventAppeared, subscriptionDropped ?? delegate { }, cancellationToken).ConfigureAwait(false)); }
public EventStorePersistentSubscriptionsClient(EventStoreClientSettings?settings) : base(settings, new Dictionary <string, Func <RpcException, Exception> > { [Constants.Exceptions.PersistentSubscriptionDoesNotExist] = ex => new PersistentSubscriptionNotFoundException( ex.Trailers.First(x => x.Key == Constants.Exceptions.StreamName).Value, ex.Trailers.First(x => x.Key == Constants.Exceptions.GroupName).Value, ex), [Constants.Exceptions.MaximumSubscribersReached] = ex => new MaximumSubscribersReachedException( ex.Trailers.First(x => x.Key == Constants.Exceptions.StreamName).Value, ex.Trailers.First(x => x.Key == Constants.Exceptions.GroupName).Value, ex), [Constants.Exceptions.PersistentSubscriptionDropped] = ex => new PersistentSubscriptionDroppedByServerException( ex.Trailers.First(x => x.Key == Constants.Exceptions.StreamName).Value, ex.Trailers.First(x => x.Key == Constants.Exceptions.GroupName).Value, ex) }) { _client = new PersistentSubscriptions.PersistentSubscriptions.PersistentSubscriptionsClient(CallInvoker); _log = Settings.LoggerFactory?.CreateLogger <EventStorePersistentSubscriptionsClient>() ?? new NullLogger <EventStorePersistentSubscriptionsClient>(); }