/// <summary> /// Initializes a new instance of the <see cref="EventHubProducerClient"/> class. /// </summary> /// /// <param name="connection">The <see cref="EventHubConnection" /> connection to use for communication with the Event Hubs service.</param> /// <param name="clientOptions">A set of options to apply when configuring the producer.</param> /// public EventHubProducerClient(EventHubConnection connection, EventHubProducerClientOptions clientOptions = default) { Argument.AssertNotNull(connection, nameof(connection)); clientOptions = clientOptions?.Clone() ?? new EventHubProducerClientOptions(); OwnsConnection = false; Connection = connection; RetryPolicy = clientOptions.RetryOptions.ToRetryPolicy(); EventHubProducer = Connection.CreateTransportProducer(null, RetryPolicy); }
/// <summary> /// Initializes a new instance of the <see cref="EventHubProducerClient"/> class. /// </summary> /// /// <param name="connectionString">The connection string to use for connecting to the Event Hubs namespace; it is expected that the shared key properties are contained in this connection string, but not the Event Hub name.</param> /// <param name="eventHubName">The name of the specific Event Hub to associate the producer with.</param> /// <param name="clientOptions">A set of options to apply when configuring the producer.</param> /// /// <remarks> /// If the connection string is copied from the Event Hub itself, it will contain the name of the desired Event Hub, /// and can be used directly without passing the <paramref name="eventHubName" />. The name of the Event Hub should be /// passed only once, either as part of the connection string or separately. /// </remarks> /// /// <seealso href="https://docs.microsoft.com/en-us/azure/event-hubs/event-hubs-get-connection-string"/> /// public EventHubProducerClient(string connectionString, string eventHubName, EventHubProducerClientOptions clientOptions) { Argument.AssertNotNullOrEmpty(connectionString, nameof(connectionString)); clientOptions = clientOptions?.Clone() ?? new EventHubProducerClientOptions(); OwnsConnection = true; Connection = new EventHubConnection(connectionString, eventHubName, clientOptions.ConnectionOptions); RetryPolicy = clientOptions.RetryOptions.ToRetryPolicy(); EventHubProducer = Connection.CreateTransportProducer(null, RetryPolicy); }
/// <summary> /// Initializes a new instance of the <see cref="EventHubProducerClient"/> class. /// </summary> /// /// <param name="fullyQualifiedNamespace">The fully qualified Event Hubs namespace to connect to. This is likely to be similar to <c>{yournamespace}.servicebus.windows.net</c>.</param> /// <param name="eventHubName">The name of the specific Event Hub to associate the producer with.</param> /// <param name="credential">The Azure managed identity credential to use for authorization. Access controls may be specified by the Event Hubs namespace or the requested Event Hub, depending on Azure configuration.</param> /// <param name="clientOptions">A set of options to apply when configuring the producer.</param> /// public EventHubProducerClient(string fullyQualifiedNamespace, string eventHubName, TokenCredential credential, EventHubProducerClientOptions clientOptions = default) { Argument.AssertWellFormedEventHubsNamespace(fullyQualifiedNamespace, nameof(fullyQualifiedNamespace)); Argument.AssertNotNullOrEmpty(eventHubName, nameof(eventHubName)); Argument.AssertNotNull(credential, nameof(credential)); clientOptions = clientOptions?.Clone() ?? new EventHubProducerClientOptions(); OwnsConnection = true; Connection = new EventHubConnection(fullyQualifiedNamespace, eventHubName, credential, clientOptions.ConnectionOptions); RetryPolicy = clientOptions.RetryOptions.ToRetryPolicy(); EventHubProducer = Connection.CreateTransportProducer(null, RetryPolicy); }