Ejemplo n.º 1
0
        /// <summary>
        ///   Creates an event receiver responsible for reading <see cref="EventData" /> from a specific Event Hub partition,
        ///   and as a member of a specific consumer group.
        ///
        ///   A receiver may be exclusive, which asserts ownership over the partition for the consumer
        ///   group to ensure that only one receiver from that group is reading the from the partition.
        ///   These exclusive receivers are sometimes referred to as "Epoch Receivers."
        ///
        ///   A receiver may also be non-exclusive, allowing multiple receivers from the same consumer
        ///   group to be actively reading events from the partition.  These non-exclusive receivers are
        ///   sometimes referred to as "Non-epoch Receivers."
        ///
        ///   Designating a receiver as exclusive may be specified in the <paramref name="receiverOptions" />.
        ///   By default, receivers are created as non-exclusive.
        /// </summary>
        ///
        /// <param name="partitionId">The identifier of the Event Hub partition from which events will be received.</param>
        /// <param name="receiverOptions">The set of options to apply when creating the receiver.</param>
        ///
        /// <returns>An event receiver configured in the requested manner.</returns>
        ///
        /// <remarks>
        ///   If the starting event position is not specified in the <paramref name="receiverOptions"/>, the receiver will
        ///   default to ignoring events in the partition that were queued prior to the receiver being created and read only
        ///   events which appear after that point.
        /// </remarks>
        ///
        public virtual EventReceiver CreateReceiver(string partitionId,
                                                    EventReceiverOptions receiverOptions = default)
        {
            Guard.ArgumentNotNullOrEmpty(nameof(partitionId), partitionId);

            var options = receiverOptions?.Clone() ?? new EventReceiverOptions {
                Retry = null, DefaultMaximumReceiveWaitTime = null
            };

            options.Retry = options.Retry ?? ClientOptions.Retry.Clone();
            options.DefaultMaximumReceiveWaitTime = options.MaximumReceiveWaitTimeOrDefault ?? ClientOptions.DefaultTimeout;

            return(InnerClient.CreateReceiver(partitionId, options));
        }
Ejemplo n.º 2
0
        /// <summary>
        ///   Initializes a new instance of the <see cref="EventReceiver"/> class.
        /// </summary>
        ///
        /// <param name="transportReceiver">An abstracted Event Receiver specific to the active protocol and transport intended to perform delegated operations.</param>
        /// <param name="eventHubPath">The path of the Event Hub from which events will be received.</param>
        /// <param name="partitionId">The identifier of the Event Hub partition from which events will be received.</param>
        /// <param name="receiverOptions">The set of options to use for this receiver.</param>
        ///
        /// <remarks>
        ///   If the starting event position is not specified in the <paramref name="receiverOptions"/>, the receiver will
        ///   default to ignoring events in the partition that were queued prior to the receiver being created and read only
        ///   events which appear after that point.
        ///
        ///   Because this is a non-public constructor, it is assumed that the <paramref name="receiverOptions" /> passed are
        ///   owned by this instance and are safe from changes made by consumers.  It is considered the responsibility of the
        ///   caller to ensure that any needed cloning of options is performed.
        /// </remarks>
        ///
        internal EventReceiver(TransportEventReceiver transportReceiver,
                               string eventHubPath,
                               string partitionId,
                               EventReceiverOptions receiverOptions)
        {
            Guard.ArgumentNotNull(nameof(transportReceiver), transportReceiver);
            Guard.ArgumentNotNullOrEmpty(nameof(eventHubPath), eventHubPath);
            Guard.ArgumentNotNullOrEmpty(nameof(partitionId), partitionId);
            Guard.ArgumentNotNull(nameof(receiverOptions), receiverOptions);

            PartitionId               = partitionId;
            StartingPosition          = receiverOptions.BeginReceivingAt;
            ExclusiveReceiverPriority = receiverOptions.ExclusiveReceiverPriority;
            ConsumerGroup             = receiverOptions.ConsumerGroup;
            Options       = receiverOptions;
            InnerReceiver = transportReceiver;
        }