private async Task CloseReceiver(CancellationToken cancellationToken)
        {
            if (_receiver == null || _receiver.IsDisposed)
            {
                return;
            }
            try
            {
                if (_sessionCloseHandler != null)
                {
                    var args = new ProcessSessionEventArgs(_receiver, cancellationToken);
                    await _sessionCloseHandler(args).ConfigureAwait(false);
                }
            }
            catch (Exception exception)
            {
                await RaiseExceptionReceived(
                    new ProcessErrorEventArgs(
                        exception,
                        ServiceBusErrorSource.CloseMessageSession,
                        _fullyQualifiedNamespace,
                        _entityPath))
                .ConfigureAwait(false);
            }
            finally
            {
                // cancel the automatic session lock renewal
                await CancelTask(_sessionLockRenewalCancellationSource, _sessionLockRenewalTask).ConfigureAwait(false);

                // Always at least attempt to dispose. If this fails, it won't be retried.
                await _receiver.DisposeAsync().ConfigureAwait(false);

                _receiver = null;
            }
        }
示例#2
0
        private async Task CloseReceiver(CancellationToken cancellationToken)
        {
            if (_receiver == null)
            {
                return;
            }

            try
            {
                if (Processor._sessionClosingAsync != null)
                {
                    var args = new ProcessSessionEventArgs(_receiver, cancellationToken);
                    await Processor.OnSessionClosingAsync(args).ConfigureAwait(false);
                }
            }
            catch (Exception exception)
            {
                await RaiseExceptionReceived(
                    new ProcessErrorEventArgs(
                        exception,
                        ServiceBusErrorSource.CloseSession,
                        Processor.FullyQualifiedNamespace,
                        Processor.EntityPath,
                        cancellationToken))
                .ConfigureAwait(false);
            }
            finally
            {
                // cancel the automatic session lock renewal
                try
                {
                    if (_sessionLockRenewalCancellationSource != null)
                    {
                        _sessionLockRenewalCancellationSource.Cancel();
                        _sessionLockRenewalCancellationSource.Dispose();
                        await _sessionLockRenewalTask.ConfigureAwait(false);
                    }
                }
                catch (Exception ex) when(ex is TaskCanceledException)
                {
                    // Nothing to do here.  These exceptions are expected.
                }

                try
                {
                    // Always at least attempt to dispose. If this fails, it won't be retried.
                    await _receiver.DisposeAsync().ConfigureAwait(false);
                }
                finally
                {
                    // If we call DisposeAsync, we need to reset to null even if DisposeAsync throws, otherwise we can
                    // end up in a bad state.
                    _receiver       = null;
                    _receiveTimeout = false;
                }
            }
        }
示例#3
0
        private async Task CreateAndInitializeSessionReceiver(
            CancellationToken cancellationToken)
        {
            await CreateReceiver(cancellationToken).ConfigureAwait(false);

            if (AutoRenewLock)
            {
                _sessionLockRenewalTask = RenewSessionLock(cancellationToken);
            }

            if (_sessionInitHandler != null)
            {
                var args = new ProcessSessionEventArgs(_receiver, cancellationToken);
                await _sessionInitHandler(args).ConfigureAwait(false);
            }
        }
示例#4
0
        private async Task CreateAndInitializeSessionReceiver(CancellationToken processorCancellationToken)
        {
            await CreateReceiver(processorCancellationToken).ConfigureAwait(false);

            _sessionCancellationSource = new CancellationTokenSource();

            if (AutoRenewLock)
            {
                _sessionLockRenewalTask = RenewSessionLock();
            }

            if (Processor._sessionInitializingAsync != null)
            {
                var args = new ProcessSessionEventArgs(_receiver, processorCancellationToken);
                await Processor.OnSessionInitializingAsync(args).ConfigureAwait(false);
            }
        }
        private async Task CreateAndInitializeSessionReceiver(
            CancellationToken cancellationToken)
        {
            _receiver = await ServiceBusSessionReceiver.CreateSessionReceiverAsync(
                entityPath : _entityPath,
                connection : _connection,
                options : _sessionReceiverOptions,
                cancellationToken : cancellationToken).ConfigureAwait(false);

            if (AutoRenewLock)
            {
                _sessionLockRenewalTask = RenewSessionLock(cancellationToken);
            }

            if (_sessionInitHandler != null)
            {
                var args = new ProcessSessionEventArgs(_receiver, cancellationToken);
                await _sessionInitHandler(args).ConfigureAwait(false);
            }
        }
示例#6
0
 /// <summary>
 /// Invokes the session close event handler when a session is about to be closed for processing.
 /// This method can be overriden to raise an event manually for testing purposes.
 /// </summary>
 /// <param name="args">The event args containing information related to the session.</param>
 protected internal virtual async Task OnSessionClosingAsync(ProcessSessionEventArgs args)
 {
     await InnerProcessor.OnSessionClosingAsync(args).ConfigureAwait(false);
 }