public async Task UnsubscribeAsync(StreamSubscriptionHandle <T> handle) { _ = RequestContextExtensions.SuppressCurrentCallChainFlow(); await BindExtensionLazy(); StreamSubscriptionHandleImpl <T> handleImpl = CheckHandleValidity(handle); if (logger.IsEnabled(LogLevel.Debug)) { logger.LogDebug("Unsubscribe StreamSubscriptionHandle={Handle}", handle); } myExtension.RemoveObserver(handleImpl.SubscriptionId); // UnregisterConsumer from pubsub even if does not have this handle locally, to allow UnsubscribeAsync retries. if (logger.IsEnabled(LogLevel.Debug)) { logger.LogDebug("Unsubscribe - Disconnecting from Rendezvous {PubSub} My GrainRef={GrainReference}", pubSub, myGrainReference); } await pubSub.UnregisterConsumer(handleImpl.SubscriptionId, stream.InternalStreamId); handleImpl.Invalidate(); }
public async Task UnsubscribeAsync(StreamSubscriptionHandle <T> handle) { await BindExtensionLazy(); StreamSubscriptionHandleImpl <T> handleImpl = CheckHandleValidity(handle); if (logger.IsVerbose) { logger.Verbose("Unsubscribe StreamSubscriptionHandle={0}", handle); } bool shouldUnsubscribe = myExtension.RemoveObserver(handle); if (!shouldUnsubscribe) { return; } if (logger.IsVerbose) { logger.Verbose("Unsubscribe - Disconnecting from Rendezvous {0} My GrainRef={1}", pubSub, myGrainReference); } await pubSub.UnregisterConsumer(handleImpl.SubscriptionId, stream.StreamId, streamProviderName); handleImpl.Invalidate(); }
private async Task DeliverToRemote(IStreamConsumerExtension remoteConsumer, StreamId streamId, GuidId subscriptionId, object item, bool optimizeForImmutableData, bool fireAndForgetDelivery) { try { if (optimizeForImmutableData) { await remoteConsumer.DeliverImmutable(subscriptionId, streamId, new Immutable <object>(item), null, null); } else { await remoteConsumer.DeliverMutable(subscriptionId, streamId, item, null, null); } } catch (ClientNotAvailableException) { Tuple <IStreamConsumerExtension, IStreamFilterPredicateWrapper> discard; if (consumers.TryRemove(subscriptionId, out discard)) { streamPubSub.UnregisterConsumer(subscriptionId, streamId, streamId.ProviderName).Ignore(); logger.Warn(ErrorCode.Stream_ConsumerIsDead, "Consumer {0} on stream {1} is no longer active - permanently removing Consumer.", remoteConsumer, streamId); } } catch (Exception ex) { if (!fireAndForgetDelivery) { throw; } this.logger.LogWarning(ex, "Failed to deliver message to consumer on {SubscriptionId} for stream {StreamId}.", subscriptionId, streamId); } }
public async Task UnsubscribeAsync(StreamSubscriptionHandle <T> handle) { await BindExtensionLazy(); if (logger.IsVerbose) { logger.Verbose("Unsubscribe StreamSubscriptionHandle={0}", handle); } bool shouldUnsubscribe = myExtension.RemoveObserver(handle); if (!shouldUnsubscribe) { return; } try { if (logger.IsVerbose) { logger.Verbose("Unsubscribe - Disconnecting from Rendezvous {0} My GrainRef={1}", pubSub, myGrainReference); } await pubSub.UnregisterConsumer(stream.StreamId, streamProviderName, myGrainReference); } finally { connectedToRendezvous = false; } }
private async Task <bool> ErrorProtocol(StreamConsumerData consumerData, Exception exceptionOccured, bool isDeliveryError, IBatchContainer batch, StreamSequenceToken token) { // for loss of client, we just remove the subscription if (exceptionOccured is ClientNotAvailableException) { logger.LogWarning( (int)ErrorCode.Stream_ConsumerIsDead, "Consumer {Consumer} on stream {StreamId} is no longer active - permanently removing Consumer.", consumerData.StreamConsumer, consumerData.StreamId); pubSub.UnregisterConsumer(consumerData.SubscriptionId, consumerData.StreamId).Ignore(); return(true); } // notify consumer about the error or that the data is not available. await OrleansTaskExtentions.ExecuteAndIgnoreException( () => DeliverErrorToConsumer( consumerData, exceptionOccured, batch)); // record that there was a delivery failure if (isDeliveryError) { await OrleansTaskExtentions.ExecuteAndIgnoreException( () => streamFailureHandler.OnDeliveryFailure( consumerData.SubscriptionId, streamProviderName, consumerData.StreamId, token)); } else { await OrleansTaskExtentions.ExecuteAndIgnoreException( () => streamFailureHandler.OnSubscriptionFailure( consumerData.SubscriptionId, streamProviderName, consumerData.StreamId, token)); } // if configured to fault on delivery failure and this is not an implicit subscription, fault and remove the subscription if (streamFailureHandler.ShouldFaultSubsriptionOnError && !SubscriptionMarker.IsImplicitSubscription(consumerData.SubscriptionId.Guid)) { try { // notify consumer of faulted subscription, if we can. await OrleansTaskExtentions.ExecuteAndIgnoreException( () => DeliverErrorToConsumer( consumerData, new FaultedSubscriptionException(consumerData.SubscriptionId, consumerData.StreamId), batch)); // mark subscription as faulted. await pubSub.FaultSubscription(consumerData.StreamId, consumerData.SubscriptionId); } finally { // remove subscription RemoveSubscriber_Impl(consumerData.SubscriptionId, consumerData.StreamId); } return(true); } return(false); }
public async Task UnsubscribeAsync(StreamSubscriptionHandle <T> handle) { await BindExtensionLazy(); StreamSubscriptionHandleImpl <T> handleImpl = CheckHandleValidity(handle); if (logger.IsVerbose) { logger.Verbose("Unsubscribe StreamSubscriptionHandle={0}", handle); } myExtension.RemoveObserver(handleImpl.SubscriptionId); // UnregisterConsumer from pubsub even if does not have this handle localy, to allow UnsubscribeAsync retries. if (logger.IsVerbose) { logger.Verbose("Unsubscribe - Disconnecting from Rendezvous {0} My GrainRef={1}", pubSub, myGrainReference); } await pubSub.UnregisterConsumer(handleImpl.SubscriptionId, stream.StreamId, streamProviderName); handleImpl.Invalidate(); }
public async Task RemoveSubscription(string streamProviderName, StreamId streamId, Guid subscriptionId) { var internalStreamId = new InternalStreamId(streamProviderName, streamId); await streamPubSub.UnregisterConsumer(GuidId.GetGuidId(subscriptionId), internalStreamId); }
public Task UnregisterConsumer(GuidId subscriptionId, InternalStreamId streamId) { return(implicitPubSub.IsImplicitSubscriber(subscriptionId, streamId) ? implicitPubSub.UnregisterConsumer(subscriptionId, streamId) : explicitPubSub.UnregisterConsumer(subscriptionId, streamId)); }
Task IStreamPubSub.UnregisterConsumer(GuidId subscriptionId, StreamId streamId, string streamProvider) { return(registry.UnregisterConsumer(subscriptionId, streamId, streamProvider)); }
public async Task <StreamSubscriptionHandle <T> > ResumeAsync( StreamSubscriptionHandle <T> handle, IAsyncObserver <T> observer, StreamSequenceToken token = null) { StreamSubscriptionHandleImpl <T> oldHandleImpl = CheckHandleValidity(handle); if (token != null && !IsRewindable) { throw new ArgumentNullException("token", "Passing a non-null token to a non-rewindable IAsyncObservable."); } if (logger.IsVerbose) { logger.Verbose("Resume Observer={0} Token={1}", observer, token); } await BindExtensionLazy(); if (logger.IsVerbose) { logger.Verbose("Resume - Connecting to Rendezvous {0} My GrainRef={1} Token={2}", pubSub, myGrainReference, token); } GuidId subscriptionId; if (token != null) { subscriptionId = pubSub.CreateSubscriptionId(myGrainReference, stream.StreamId); // otherwise generate a new subscriptionId await pubSub.RegisterConsumer(subscriptionId, stream.StreamId, streamProviderName, myGrainReference, token, null); try { await UnsubscribeAsync(handle); } catch (Exception exc) { // best effort cleanup of newly established subscription pubSub.UnregisterConsumer(subscriptionId, stream.StreamId, streamProviderName) .LogException(logger, ErrorCode.StreamProvider_FailedToUnsubscribeFromPubSub, String.Format("Stream consumer could not clean up subscription {0} while recovering from errors renewing subscription {1} on stream {2}.", subscriptionId, oldHandleImpl.SubscriptionId, stream.StreamId)) .Ignore(); logger.Error(ErrorCode.StreamProvider_FailedToUnsubscribeFromPubSub, String.Format("Stream consumer failed to unsubscrive from subscription {0} while renewing subscription on stream {1}.", oldHandleImpl.SubscriptionId, stream.StreamId), exc); throw; } } else { subscriptionId = oldHandleImpl.SubscriptionId; } StreamSubscriptionHandle <T> newHandle = myExtension.SetObserver(subscriptionId, stream, observer, null); // On failure caller should be able to retry using the original handle, so invalidate old handle only if everything succeeded. oldHandleImpl.Invalidate(); return(newHandle); }
public async Task RemoveSubscription(string streamProviderName, IStreamIdentity streamId, Guid subscriptionId) { await streamPubSub.UnregisterConsumer(GuidId.GetGuidId(subscriptionId), StreamId.GetStreamId(streamId.Guid, streamProviderName, streamId.Namespace), streamProviderName); }
public Task UnregisterConsumer(GuidId subscriptionId, StreamId streamId, string streamProvider) { return(IsImplicitSubscriber(subscriptionId, streamId) ? TaskDone.Done : explicitPubSub.UnregisterConsumer(subscriptionId, streamId, streamProvider)); }
public Task UnregisterConsumer(StreamId streamId, string streamProvider, IStreamConsumerExtension streamConsumer) { return(IsImplicitSubscriber(streamConsumer, streamId) ? TaskDone.Done : explicitPubSub.UnregisterConsumer(streamId, streamProvider, streamConsumer)); }
public async Task RemoveSubscription(IStreamIdentity streamId, Guid subscriptionId) { var streamProviderName = this.name; await streamPubSub.UnregisterConsumer(GuidId.GetGuidId(subscriptionId), (StreamId)streamId, streamProviderName); }