/// <summary> /// Initializes a new instance of the <see cref="EventHubConsumerClient"/> class. /// </summary> /// /// <param name="consumerGroup">The name of the consumer group this consumer is associated with. Events are read in the context of this group.</param> /// <param name="partitionId">The identifier of the Event Hub partition from which events will be received.</param> /// <param name="eventPosition">The position within the partition where the consumer should begin reading events.</param> /// <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="consumerOptions">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 EventHubConsumerClient(string consumerGroup, string partitionId, EventPosition eventPosition, string connectionString, EventHubConsumerClientOptions consumerOptions) : this(consumerGroup, partitionId, eventPosition, connectionString, null, consumerOptions) { }
/// <summary> /// Initializes a new instance of the <see cref="EventHubConsumerClient"/> class. /// </summary> /// /// <param name="consumerGroup">The name of the consumer group this consumer is associated with. Events are read in the context of this group.</param> /// <param name="partitionId">The identifier of the Event Hub partition from which events will be received.</param> /// <param name="eventPosition">The position within the partition where the consumer should begin reading events.</param> /// <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 consumer 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="consumerOptions">A set of options to apply when configuring the consumer.</param> /// public EventHubConsumerClient(string consumerGroup, string partitionId, EventPosition eventPosition, string fullyQualifiedNamespace, string eventHubName, TokenCredential credential, EventHubConsumerClientOptions consumerOptions = default) { Argument.AssertNotNullOrEmpty(consumerGroup, nameof(consumerGroup)); Argument.AssertNotNullOrEmpty(partitionId, nameof(partitionId)); Argument.AssertNotNull(eventPosition, nameof(eventPosition)); Argument.AssertNotNullOrEmpty(fullyQualifiedNamespace, nameof(fullyQualifiedNamespace)); Argument.AssertNotNullOrEmpty(eventHubName, nameof(eventHubName)); Argument.AssertNotNull(credential, nameof(credential)); consumerOptions = consumerOptions?.Clone() ?? new EventHubConsumerClientOptions(); OwnsConnection = true; Connection = new EventHubConnection(fullyQualifiedNamespace, eventHubName, credential, consumerOptions.ConnectionOptions); ConsumerGroup = consumerGroup; Options = consumerOptions; RetryPolicy = consumerOptions.RetryOptions.ToRetryPolicy(); InnerConsumer = Connection.CreateTransportConsumer(consumerGroup, partitionId, eventPosition, consumerOptions); PartitionId = partitionId; StartingPosition = eventPosition; }
/// <summary> /// Creates a consumer strongly aligned with the active protocol and transport, responsible /// for reading <see cref="EventData" /> from a specific Event Hub partition, in the context /// of a specific consumer group. /// /// A consumer may be exclusive, which asserts ownership over the partition for the consumer /// group to ensure that only one consumer from that group is reading the from the partition. /// These exclusive consumers are sometimes referred to as "Epoch Consumers." /// /// A consumer may also be non-exclusive, allowing multiple consumers from the same consumer /// group to be actively reading events from the partition. These non-exclusive consumers are /// sometimes referred to as "Non-epoch Consumers." /// /// Designating a consumer as exclusive may be specified in the <paramref name="consumerOptions" />. /// By default, consumers are created as non-exclusive. /// </summary> /// /// <param name="consumerGroup">The name of the consumer group this consumer is associated with. Events are read in the context of this group.</param> /// <param name="partitionId">The identifier of the Event Hub partition from which events will be received.</param> /// <param name="eventPosition">The position within the partition where the consumer should begin reading events.</param> /// <param name="consumerOptions">The set of options to apply when creating the consumer.</param> /// /// <returns>A <see cref="TransportConsumer"/> configured in the requested manner.</returns> /// internal virtual TransportConsumer CreateTransportConsumer(string consumerGroup, string partitionId, EventPosition eventPosition, EventHubConsumerClientOptions consumerOptions = default) { Argument.AssertNotNullOrEmpty(consumerGroup, nameof(consumerGroup)); Argument.AssertNotNullOrEmpty(partitionId, nameof(partitionId)); return(InnerClient.CreateConsumer(consumerGroup, partitionId, eventPosition, consumerOptions?.Clone() ?? new EventHubConsumerClientOptions())); }
/// <summary> /// Initializes a new instance of the <see cref="EventHubConsumerClient"/> class. /// </summary> /// /// <param name="consumerGroup">The name of the consumer group this consumer is associated with. Events are read in the context of this group.</param> /// <param name="connection">The <see cref="EventHubConnection" /> connection to use for communication with the Event Hubs service.</param> /// <param name="consumerOptions">A set of options to apply when configuring the consumer.</param> /// public EventHubConsumerClient(string consumerGroup, EventHubConnection connection, EventHubConsumerClientOptions consumerOptions = default) { Argument.AssertNotNullOrEmpty(consumerGroup, nameof(consumerGroup)); Argument.AssertNotNull(connection, nameof(connection)); consumerOptions = consumerOptions?.Clone() ?? new EventHubConsumerClientOptions(); OwnsConnection = false; Connection = connection; ConsumerGroup = consumerGroup; Options = consumerOptions; RetryPolicy = consumerOptions.RetryOptions.ToRetryPolicy(); }
/// <summary> /// Initializes a new instance of the <see cref="EventHubConsumerClient"/> class. /// </summary> /// /// <param name="consumerGroup">The name of the consumer group this consumer is associated with. Events are read in the context of this group.</param> /// <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 consumer with.</param> /// <param name="consumerOptions">A set of options to apply when configuring the consumer.</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 EventHubConsumerClient(string consumerGroup, string connectionString, string eventHubName, EventHubConsumerClientOptions consumerOptions) { Argument.AssertNotNullOrEmpty(consumerGroup, nameof(consumerGroup)); Argument.AssertNotNullOrEmpty(connectionString, nameof(connectionString)); consumerOptions = consumerOptions?.Clone() ?? new EventHubConsumerClientOptions(); OwnsConnection = true; Connection = new EventHubConnection(connectionString, eventHubName, consumerOptions.ConnectionOptions); ConsumerGroup = consumerGroup; Options = consumerOptions; RetryPolicy = consumerOptions.RetryOptions.ToRetryPolicy(); }
/// <summary> /// Initializes a new instance of the <see cref="EventHubConsumerClient"/> class. /// </summary> /// /// <param name="consumerGroup">The name of the consumer group this consumer is associated with. Events are read in the context of this group.</param> /// <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 consumer 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="consumerOptions">A set of options to apply when configuring the consumer.</param> /// public EventHubConsumerClient(string consumerGroup, string fullyQualifiedNamespace, string eventHubName, TokenCredential credential, EventHubConsumerClientOptions consumerOptions = default) { Argument.AssertNotNullOrEmpty(consumerGroup, nameof(consumerGroup)); Argument.AssertNotNullOrEmpty(fullyQualifiedNamespace, nameof(fullyQualifiedNamespace)); Argument.AssertNotNullOrEmpty(eventHubName, nameof(eventHubName)); Argument.AssertNotNull(credential, nameof(credential)); consumerOptions = consumerOptions?.Clone() ?? new EventHubConsumerClientOptions(); OwnsConnection = true; Connection = new EventHubConnection(fullyQualifiedNamespace, eventHubName, credential, consumerOptions.ConnectionOptions); ConsumerGroup = consumerGroup; Options = consumerOptions; RetryPolicy = consumerOptions.RetryOptions.ToRetryPolicy(); }
/// <summary> /// Initializes a new instance of the <see cref="EventHubConsumerClient"/> class. /// </summary> /// /// <param name="consumerGroup">The name of the consumer group this consumer is associated with. Events are read in the context of this group.</param> /// <param name="partitionId">The identifier of the Event Hub partition from which events will be received.</param> /// <param name="eventPosition">The position within the partition where the consumer should begin reading events.</param> /// <param name="connection">The <see cref="EventHubConnection" /> connection to use for communication with the Event Hubs service.</param> /// <param name="consumerOptions">A set of options to apply when configuring the consumer.</param> /// public EventHubConsumerClient(string consumerGroup, string partitionId, EventPosition eventPosition, EventHubConnection connection, EventHubConsumerClientOptions consumerOptions = default) { Argument.AssertNotNullOrEmpty(consumerGroup, nameof(consumerGroup)); Argument.AssertNotNullOrEmpty(partitionId, nameof(partitionId)); Argument.AssertNotNull(eventPosition, nameof(eventPosition)); Argument.AssertNotNull(connection, nameof(connection)); consumerOptions = consumerOptions?.Clone() ?? new EventHubConsumerClientOptions(); OwnsConnection = false; Connection = connection; ConsumerGroup = consumerGroup; Options = consumerOptions; RetryPolicy = consumerOptions.RetryOptions.ToRetryPolicy(); InnerConsumer = Connection.CreateTransportConsumer(consumerGroup, partitionId, eventPosition, consumerOptions); PartitionId = partitionId; StartingPosition = eventPosition; }
/// <summary> /// Initializes a new instance of the <see cref="EventHubConsumerClient"/> class. /// </summary> /// /// <param name="consumerGroup">The name of the consumer group this consumer is associated with. Events are read in the context of this group.</param> /// <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="consumerOptions">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 EventHubConsumerClient(string consumerGroup, string connectionString, EventHubConsumerClientOptions consumerOptions) : this(consumerGroup, connectionString, null, consumerOptions) { }