protected override string FromAsText()
 {
     return(_from.ToString());
 }
Example #2
0
        /// <summary>
        ///   Creates the AMQP link to be used for consumer-related operations.
        /// </summary>
        ///
        /// <param name="consumerGroup">The consumer group of the Event Hub to which the link is bound.</param>
        /// <param name="partitionId">The identifier of the Event Hub partition to which the link is bound.</param>
        /// <param name="consumerIdentifier">The identifier associated with the consumer.</param>
        /// <param name="eventStartingPosition">The place within the partition's event stream to begin consuming events.</param>
        /// <param name="prefetchCount">Controls the number of events received and queued locally without regard to whether an operation was requested.</param>
        /// <param name="prefetchSizeInBytes">The cache size of the prefetch queue. When set, the link makes a best effort to ensure prefetched messages fit into the specified size.</param>
        /// <param name="ownerLevel">The relative priority to associate with the link; for a non-exclusive link, this value should be <c>null</c>.</param>
        /// <param name="trackLastEnqueuedEventProperties">Indicates whether information on the last enqueued event on the partition is sent as events are received.</param>
        /// <param name="timeout">The timeout to apply for creating the link.</param>
        /// <param name="cancellationToken">The cancellation token to consider when creating the link.</param>
        ///
        /// <returns>The AMQP link to use for consumer-related operations.</returns>
        ///
        protected async Task <ReceivingAmqpLink> CreateConsumerLinkAsync(string consumerGroup,
                                                                         string partitionId,
                                                                         string consumerIdentifier,
                                                                         EventPosition eventStartingPosition,
                                                                         uint prefetchCount,
                                                                         long?prefetchSizeInBytes,
                                                                         long?ownerLevel,
                                                                         bool trackLastEnqueuedEventProperties,
                                                                         TimeSpan timeout,
                                                                         CancellationToken cancellationToken)
        {
            // Determine if there is an active is an active exception that needs to be surfaced,
            // do so now.
            //
            // Note that this is a benign race; it is possible that multiple threads
            // will observe the active exception and surface it, even if the consumer is not
            // considered invalid.  This is reasonable behavior for this scenario as the underlying
            // condition is itself a race condition between multiple consumers.

            var activeException = _activePartitionStolenException;

            if (activeException != null)
            {
                // If the consumer should not be considered invalid, clear the active exception if
                // it hasn't already been reset.

                if (!InvalidateConsumerWhenPartitionStolen)
                {
                    Interlocked.CompareExchange(ref _activePartitionStolenException, null, activeException);
                }

                EventHubsEventSource.Log.AmqpConsumerLinkCreateCapturedErrorThrow(EventHubName, consumerGroup, partitionId, ownerLevel?.ToString(CultureInfo.InvariantCulture), eventStartingPosition.ToString(), activeException.Message);
                ExceptionDispatchInfo.Capture(activeException).Throw();
            }

            // Create and open the consumer link.

            var link       = default(ReceivingAmqpLink);
            var tryTimeout = RetryPolicy.CalculateTryTimeout(0);

            try
            {
                link = await ConnectionScope.OpenConsumerLinkAsync(
                    consumerGroup,
                    partitionId,
                    eventStartingPosition,
                    tryTimeout,
                    timeout,
                    prefetchCount,
                    prefetchSizeInBytes,
                    ownerLevel,
                    trackLastEnqueuedEventProperties,
                    consumerIdentifier,
                    cancellationToken).ConfigureAwait(false);
            }
            catch (Exception ex)
            {
                ExceptionDispatchInfo.Capture(ex.TranslateConnectionCloseDuringLinkCreationException(EventHubName)).Throw();
            }

            return(link);
        }