예제 #1
0
        /// <summary>
        ///   Closes the AMQP link used by the consumer, capturing the passive terminal exception that triggered
        ///   closing if it should be surfaced during the next requested operation.
        /// </summary>
        ///
        protected void CloseConsumerLink(ReceivingAmqpLink link)
        {
            // If there is no link, then no action needs to be
            // taken.

            if (link == null)
            {
                return;
            }

            // If the consumer is being closed, the sentinel variable will already be set, and
            // the terminal exception need not be considered.

            if (!_closed)
            {
                var linkException = GetTerminalException(link);

                // If the terminal exception indicates that the partition was stolen from the consumer,
                // capture it so that it can be surfaced when the next operation is requested.

                if (linkException.IsConsumerPartitionStolenException())
                {
                    EventHubsEventSource.Log.AmqpConsumerLinkFaultCapture(EventHubName, ConsumerGroup, PartitionId, linkException.Message);
                    _activePartitionStolenException = linkException;
                }
            }

            // Close the link and it's associated session.

            link.Session?.SafeClose();
            link.SafeClose();

            EventHubsEventSource.Log.FaultTolerantAmqpObjectClose(nameof(ReceivingAmqpLink), "", EventHubName, ConsumerGroup, PartitionId, link.TerminalException?.Message);
        }
예제 #2
0
        public void CloseConsumerLinkIgnoresGeneralExceptions(Exception terminalException)
        {
            var eventHub     = "fake-hub";
            var link         = new ReceivingAmqpLink(new AmqpLinkSettings());
            var mockConsumer = new MockAmqpConsumer(eventHub, true, terminalException);

            try
            {
                mockConsumer.InvokeCloseConsumerLink(link);
                Assert.That(GetActivePartitionStolenException(mockConsumer), Is.Null);
            }
            finally
            {
                link?.SafeClose();
            }
        }
예제 #3
0
        public void CloseConsumerLinkDetectsAStolenPartition()
        {
            var eventHub          = "fake-hub";
            var terminalException = new AmqpException(new Error {
                Condition = AmqpErrorCode.Stolen
            });
            var link         = new ReceivingAmqpLink(new AmqpLinkSettings());
            var mockConsumer = new MockAmqpConsumer(eventHub, true, terminalException);

            try
            {
                mockConsumer.InvokeCloseConsumerLink(link);
                Assert.That(GetActivePartitionStolenException(mockConsumer), Is.SameAs(terminalException));
            }
            finally
            {
                link?.SafeClose();
            }
        }
 internal void SafeClose()
 {
     _receivingAmqpLink.SafeClose();
 }
예제 #5
0
 private void CloseLink(ReceivingAmqpLink link)
 {
     link.Session?.SafeClose();
     link.SafeClose();
 }