/// <summary> /// Force server to close current subscription worker /// </summary> /// <param name="worker"></param> /// <param name="database"></param> public async Task DropSubscriptionWorkerAsync <T>(SubscriptionWorker <T> worker, string database = null, CancellationToken token = default) where T : class { database = _store.GetDatabase(database); var requestExecutor = _store.GetRequestExecutor(database); using (requestExecutor.ContextPool.AllocateOperationContext(out var jsonOperationContext)) { var command = new DropSubscriptionConnectionCommand(worker.SubscriptionName, worker.WorkerId); await requestExecutor.ExecuteAsync(command, jsonOperationContext, sessionInfo : null, token : token).ConfigureAwait(false); } }
/// <summary> /// It opens a subscription and starts pulling documents since a last processed document for that subscription. /// The connection options determine client and server cooperation rules like document batch sizes or a timeout in a matter of which a client /// needs to acknowledge that batch has been processed. The acknowledgment is sent after all documents are processed by subscription's handlers. /// There can be only a single client that is connected to a subscription. /// </summary> /// <returns>Subscription object that allows to add/remove subscription handlers.</returns> public SubscriptionWorker <T> GetSubscriptionWorker <T>(SubscriptionWorkerOptions options, string database = null) where T : class { if (options == null) { throw new InvalidOperationException("Cannot open a subscription if options are null"); } var subscription = new SubscriptionWorker <T>(options, _store, database); subscription.OnDisposed += sender => _subscriptions.TryRemove(sender); _subscriptions.Add(subscription); return(subscription); }
/// <summary> /// Force server to close current subscription worker /// </summary> /// <param name="worker"></param> /// <param name="database"></param> public void DropSubscriptionWorker <T>(SubscriptionWorker <T> worker, string database = null) where T : class { AsyncHelpers.RunSync(() => DropSubscriptionWorkerAsync(worker, database)); }