Exemplo n.º 1
0
        /// <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);
        }
Exemplo n.º 2
0
        /// <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 Event Hub name and SAS token are contained in this connection string.</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>
        ///
        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="connection">The <see cref="EventHubConnection" /> connection to use for communication with the Event Hubs service.</param>
        /// <param name="producerOptions">A set of options to apply when configuring the producer.</param>
        ///
        public EventHubProducerClient(EventHubConnection connection,
                                      EventHubProducerClientOptions producerOptions = default)
        {
            Argument.AssertNotNull(connection, nameof(connection));
            producerOptions = producerOptions?.Clone() ?? new EventHubProducerClientOptions();

            OwnsConnection = false;
            Connection     = connection;
            PartitionId    = producerOptions.PartitionId;
            RetryPolicy    = producerOptions.RetryOptions.ToRetryPolicy();
            InnerProducer  = Connection.CreateTransportProducer(producerOptions);
        }
        /// <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 Event Hub name and SAS token are contained in this connection string.</param>
        /// <param name="eventHubName">The name of the specific Event Hub to associate the producer with.</param>
        /// <param name="producerOptions">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>
        ///
        public EventHubProducerClient(string connectionString,
                                      string eventHubName,
                                      EventHubProducerClientOptions producerOptions)
        {
            Argument.AssertNotNullOrEmpty(connectionString, nameof(connectionString));
            producerOptions = producerOptions?.Clone() ?? new EventHubProducerClientOptions();

            OwnsConnection = true;
            Connection     = new EventHubConnection(connectionString, eventHubName, producerOptions.ConnectionOptions);
            PartitionId    = producerOptions.PartitionId;
            RetryPolicy    = producerOptions.RetryOptions.ToRetryPolicy();
            InnerProducer  = Connection.CreateTransportProducer(producerOptions);
        }
        /// <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 associated 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="producerOptions">A set of options to apply when configuring the producer.</param>
        ///
        public EventHubProducerClient(string fullyQualifiedNamespace,
                                      string eventHubName,
                                      TokenCredential credential,
                                      EventHubProducerClientOptions producerOptions = default)
        {
            Argument.AssertNotNullOrEmpty(fullyQualifiedNamespace, nameof(fullyQualifiedNamespace));
            Argument.AssertNotNullOrEmpty(eventHubName, nameof(eventHubName));
            Argument.AssertNotNull(credential, nameof(credential));

            producerOptions = producerOptions?.Clone() ?? new EventHubProducerClientOptions();

            OwnsConnection  = true;
            Connection      = new EventHubConnection(fullyQualifiedNamespace, eventHubName, credential, producerOptions.ConnectionOptions);
            Options         = producerOptions;
            RetryPolicy     = producerOptions.RetryOptions.ToRetryPolicy();
            GatewayProducer = Connection.CreateTransportProducer(null, producerOptions);
        }
 /// <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 Event Hub name and SAS token are contained in this connection string.</param>
 /// <param name="producerOptions">The set of options to use for this consumer.</param>
 ///
 /// <remarks>
 ///   If the connection string is copied from the Event Hubs namespace, it will likely not contain the name of the desired Event Hub,
 ///   which is needed.  In this case, the name can be added manually by adding ";EntityPath=[[ EVENT HUB NAME ]]" to the end of the
 ///   connection string.  For example, ";EntityPath=telemetry-hub".
 ///
 ///   If you have defined a shared access policy directly on the Event Hub itself, then copying the connection string from that
 ///   Event Hub will result in a connection string that contains the name.
 /// </remarks>
 ///
 public EventHubProducerClient(string connectionString,
                               EventHubProducerClientOptions producerOptions) : this(connectionString, null, producerOptions)
 {
 }
Exemplo n.º 7
0
 /// <summary>
 ///   Creates a producer strongly aligned with the active protocol and transport,
 ///   responsible for publishing <see cref="EventData" /> to the Event Hub.
 /// </summary>
 ///
 /// <param name="producerOptions">The set of options to apply when creating the producer.</param>
 ///
 /// <returns>A <see cref="TransportProducer"/> configured in the requested manner.</returns>
 ///
 internal virtual TransportProducer CreateTransportProducer(EventHubProducerClientOptions producerOptions = default) =>
 InnerClient.CreateProducer(producerOptions?.Clone() ?? new EventHubProducerClientOptions());