예제 #1
0
        /// <summary>
        ///   Creates an event sender responsible for transmitting <see cref="EventData" /> to the
        ///   Event Hub, grouped together in batches.  Depending on the <paramref name="senderOptions"/>
        ///   specified, the sender may be created to allow event data to be automatically routed to an available
        ///   partition or specific to a partition.
        /// </summary>
        ///
        /// <param name="senderOptions">The set of options to apply when creating the sender.</param>
        ///
        /// <returns>An event sender configured in the requested manner.</returns>
        ///
        /// <remarks>
        ///   Allowing automatic routing of partitions is recommended when:
        ///   <para>- The sending of events needs to be highly available.</para>
        ///   <para>- The event data should be evenly distributed among all available partitions.</para>
        ///
        ///   If no partition is specified, the following rules are used for automatically selecting one:
        ///   <para>1) Distribute the events equally amongst all available partitions using a round-robin approach.</para>
        ///   <para>2) If a partition becomes unavailable, the Event Hubs service will automatically detect it and forward the message to another available partition.</para>
        /// </remarks>
        ///
        public virtual EventSender CreateSender(EventSenderOptions senderOptions = default)
        {
            var options = senderOptions?.Clone() ?? new EventSenderOptions {
                Retry = null, Timeout = null
            };

            options.Retry   = options.Retry ?? ClientOptions.Retry.Clone();
            options.Timeout = options.TimeoutOrDefault ?? ClientOptions.DefaultTimeout;

            return(InnerClient.CreateSender(options));
        }
예제 #2
0
        /// <summary>
        ///   Initializes a new instance of the <see cref="EventSender"/> class.
        /// </summary>
        ///
        /// <param name="transportSender">An abstracted Event Sender specific to the active protocol and transport intended to perform delegated operations.</param>
        /// <param name="eventHubPath">The path of the Event Hub to which events will be sent.</param>
        /// <param name="senderOptions">The set of options to use for this receiver.</param>
        ///
        /// <remarks>
        ///   Because this is a non-public constructor, it is assumed that the <paramref name="senderOptions" /> 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 EventSender(TransportEventSender transportSender,
                             string eventHubPath,
                             EventSenderOptions senderOptions)
        {
            Guard.ArgumentNotNull(nameof(transportSender), transportSender);
            Guard.ArgumentNotNullOrEmpty(nameof(eventHubPath), eventHubPath);
            Guard.ArgumentNotNull(nameof(senderOptions), senderOptions);

            PartitionId  = senderOptions.PartitionId;
            EventHubPath = eventHubPath;
            Options      = senderOptions;
            InnerSender  = transportSender;
        }