Exemplo n.º 1
0
        /// <summary>
        ///   Creates an Event Hub producer responsible for publishing <see cref="EventData" /> to the
        ///   Event Hub, either as a single item or grouped together in batches.  Depending on the
        ///   <paramref name="producerOptions"/> specified, the producer may be created to allow event
        ///   data to be automatically routed to an available partition or specific to a partition.
        /// </summary>
        ///
        /// <param name="producerOptions">The set of options to apply when creating the producer.</param>
        ///
        /// <returns>An Event Hub producer configured in the requested manner.</returns>
        ///
        /// <remarks>
        ///   Allowing automatic routing of partitions is recommended when:
        ///   <para>- The publishing 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>- Distribute the events equally amongst all available partitions using a round-robin approach.</para>
        ///   <para>- 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 EventHubProducer CreateProducer(EventHubProducerOptions producerOptions = default)
        {
            var options = producerOptions?.Clone() ?? new EventHubProducerOptions {
                Retry = null, Timeout = null
            };

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

            return(InnerClient.CreateProducer(options));
        }