Class EventHubBufferedProducerClient
A client responsible for publishing instances of EventData to a specific Event Hub. Depending on the options specified when events are enqueued, they may be automatically assigned to a partition, grouped according to the specified partition key, or assigned a specifically requested partition.
The EventHubBufferedProducerClient does not publish immediately, instead using a deferred model where events are collected into a buffer so that they may be efficiently batched and published when the batch is full or the MaximumWaitTime has elapsed with no new events enqueued.
This model is intended to shift the burden of batch management from callers, at the cost of non-deterministic timing, for when events will be published. There are additional trade-offs to consider, as well:
- If the application crashes, events in the buffer will not have been published. To prevent data loss, callers are encouraged to track publishing progress using the SendEventBatchSucceededAsync and SendEventBatchFailedAsync handlers.
- Events specifying a partition key may be assigned a different partition than those using the same key with other producers.
- In the unlikely event that a partition becomes temporarily unavailable, the EventHubBufferedProducerClient may take longer to recover than other producers.
In scenarios where it is important to have events published immediately with a deterministic outcome, ensure that partition keys are assigned to a partition consistent with other publishers, or where maximizing availability is a requirement, using the EventHubProducerClient is recommended.
Inheritance
Namespace: System.Dynamic.ExpandoObject
Assembly: Azure.Messaging.EventHubs.dll
Syntax
public class EventHubBufferedProducerClient : IAsyncDisposable
Remarks
The EventHubBufferedProducerClient is safe to cache and use as a singleton for the lifetime of an application, which is the recommended approach. The producer is responsible for ensuring efficient network, CPU, and memory use. Calling either CloseAsync(Boolean, CancellationToken) or DisposeAsync() when no more events will be enqueued or as the application is shutting down is required so that the buffer can be flushed and resources cleaned up properly.
Constructors
EventHubBufferedProducerClient()
Used for mocking the producer for testing purposes.
Declaration
protected EventHubBufferedProducerClient ();
EventHubBufferedProducerClient(String)
Initializes a new instance of the EventHubBufferedProducerClient class.
Declaration
public EventHubBufferedProducerClient (string connectionString);
Parameters
System.String
connectionString
The connection string to use for connecting to the Event Hubs namespace; it is expected that the Event Hub name and the shared key properties are contained in this connection string. |
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.
EventHubBufferedProducerClient(EventHubConnection, EventHubBufferedProducerClientOptions)
Initializes a new instance of the EventHubBufferedProducerClient class.
Declaration
public EventHubBufferedProducerClient (Azure.Messaging.EventHubs.EventHubConnection connection, Azure.Messaging.EventHubs.Producer.EventHubBufferedProducerClientOptions clientOptions = null);
Parameters
EventHubConnection
connection
The EventHubConnection connection to use for communication with the Event Hubs service. |
EventHubBufferedProducerClientOptions
clientOptions
A set of EventHubBufferedProducerClientOptions to apply when configuring the producer. |
EventHubBufferedProducerClient(String, EventHubBufferedProducerClientOptions)
Initializes a new instance of the EventHubBufferedProducerClient class.
Declaration
public EventHubBufferedProducerClient (string connectionString, Azure.Messaging.EventHubs.Producer.EventHubBufferedProducerClientOptions clientOptions);
Parameters
System.String
connectionString
The connection string to use for connecting to the Event Hubs namespace; it is expected that the Event Hub name and the shared key properties are contained in this connection string. |
EventHubBufferedProducerClientOptions
clientOptions
A set of EventHubBufferedProducerClientOptions to apply when configuring the buffered producer. |
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.
EventHubBufferedProducerClient(String, String)
Initializes a new instance of the EventHubBufferedProducerClient class.
Declaration
public EventHubBufferedProducerClient (string connectionString, string eventHubName);
Parameters
System.String
connectionString
The connection string to use for connecting to the Event Hubs namespace; it is expected that the Event Hub name and the shared key properties are contained in this connection string. |
System.String
eventHubName
The name of the specific Event Hub to associate the producer with. |
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 eventHubName
. The name of the Event Hub should be
passed only once, either as part of the connection string or separately.
EventHubBufferedProducerClient(String, String, EventHubBufferedProducerClientOptions)
Initializes a new instance of the EventHubBufferedProducerClient class.
Declaration
public EventHubBufferedProducerClient (string connectionString, string eventHubName, Azure.Messaging.EventHubs.Producer.EventHubBufferedProducerClientOptions clientOptions);
Parameters
System.String
connectionString
The connection string to use for connecting to the Event Hubs namespace; it is expected that the Event Hub name and the shared key properties are contained in this connection string. |
System.String
eventHubName
The name of the specific Event Hub to associate the producer with. |
EventHubBufferedProducerClientOptions
clientOptions
A set of EventHubBufferedProducerClientOptions to apply when configuring the buffered producer. |
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 eventHubName
. The name of the Event Hub should be
passed only once, either as part of the connection string or separately.
EventHubBufferedProducerClient(String, String, AzureNamedKeyCredential, EventHubBufferedProducerClientOptions)
Initializes a new instance of the EventHubBufferedProducerClient class.
Declaration
public EventHubBufferedProducerClient (string fullyQualifiedNamespace, string eventHubName, Azure.AzureNamedKeyCredential credential, Azure.Messaging.EventHubs.Producer.EventHubBufferedProducerClientOptions clientOptions = null);
Parameters
System.String
fullyQualifiedNamespace
The fully qualified Event Hubs namespace to connect to. This is likely to be similar to |
System.String
eventHubName
The name of the specific Event Hub to associate the producer with. |
Azure.AzureNamedKeyCredential
credential
The shared access key credential to use for authorization. Access controls may be specified by the Event Hubs namespace or the requested Event Hub, depending on Azure configuration. |
EventHubBufferedProducerClientOptions
clientOptions
A set of EventHubBufferedProducerClientOptions to apply when configuring the producer. |
EventHubBufferedProducerClient(String, String, AzureSasCredential, EventHubBufferedProducerClientOptions)
Initializes a new instance of the EventHubBufferedProducerClient class.
Declaration
public EventHubBufferedProducerClient (string fullyQualifiedNamespace, string eventHubName, Azure.AzureSasCredential credential, Azure.Messaging.EventHubs.Producer.EventHubBufferedProducerClientOptions clientOptions = null);
Parameters
System.String
fullyQualifiedNamespace
The fully qualified Event Hubs namespace to connect to. This is likely to be similar to |
System.String
eventHubName
The name of the specific Event Hub to associate the producer with. |
Azure.AzureSasCredential
credential
The shared access key credential to use for authorization. Access controls may be specified by the Event Hubs namespace or the requested Event Hub, depending on Azure configuration. |
EventHubBufferedProducerClientOptions
clientOptions
A set of EventHubBufferedProducerClientOptions to apply when configuring the producer. |
EventHubBufferedProducerClient(String, String, TokenCredential, EventHubBufferedProducerClientOptions)
Initializes a new instance of the EventHubBufferedProducerClient class.
Declaration
public EventHubBufferedProducerClient (string fullyQualifiedNamespace, string eventHubName, Azure.Core.TokenCredential credential, Azure.Messaging.EventHubs.Producer.EventHubBufferedProducerClientOptions clientOptions = null);
Parameters
System.String
fullyQualifiedNamespace
The fully qualified Event Hubs namespace to connect to. This is likely to be similar to |
System.String
eventHubName
The name of the specific Event Hub to associate the producer with. |
Azure.Core.TokenCredential
credential
The shared access key credential to use for authorization. Access controls may be specified by the Event Hubs namespace or the requested Event Hub, depending on Azure configuration. |
EventHubBufferedProducerClientOptions
clientOptions
A set of EventHubBufferedProducerClientOptions to apply when configuring the producer. |
Properties
EventHubName
The name of the Event Hub that this producer is connected to, specific to the Event Hubs namespace that contains it.
Declaration
public string EventHubName { get; }
Property Value
System.String
|
FullyQualifiedNamespace
The fully qualified Event Hubs namespace that this producer is currently associated with, which will likely be similar
to {yournamespace}.servicebus.windows.net
.
Declaration
public string FullyQualifiedNamespace { get; }
Property Value
System.String
|
Identifier
A unique name to identify the buffered producer.
Declaration
public string Identifier { get; }
Property Value
System.String
|
IsClosed
Indicates whether or not this EventHubBufferedProducerClient has been closed.
Declaration
public virtual bool IsClosed { get; }
Property Value
System.Boolean
|
IsPublishing
Indicates whether or not this EventHubBufferedProducerClient is currently active and publishing queued events.
Declaration
public virtual bool IsPublishing { get; }
Property Value
System.Boolean
|
Remarks
The producer will begin publishing when an event is enqueued and should remain active until either CloseAsync(Boolean, CancellationToken) or DisposeAsync() is called.
If any events were enqueued, IsClosed is false
, and IsPublishing
is false
, this likely indicates an unrecoverable state for the client. It is recommended to
close the EventHubBufferedProducerClient and create a new instance.
In this state, exceptions will be reported by the Event Hubs client library logs, which can be captured using the Azure.Core.Diagnostics.AzureEventSourceListener.
TotalBufferedEventCount
The total number of events that are currently buffered and waiting to be published, across all partitions.
Declaration
public virtual int TotalBufferedEventCount { get; }
Property Value
System.Int32
|
Methods
CloseAsync(Boolean, CancellationToken)
Closes the producer and performs the tasks needed to clean up all the resources used by the EventHubBufferedProducerClient.
Declaration
[System.Diagnostics.DebuggerStepThrough]
public virtual System.Threading.Tasks.Task CloseAsync (bool flush = true, System.Threading.CancellationToken cancellationToken = null);
Parameters
System.Boolean
flush
|
System.Threading.CancellationToken
cancellationToken
An optional System.Threading.CancellationToken instance to signal the request to cancel the operation. |
Returns
System.Threading.Tasks.Task
A task to be resolved on when the operation has completed. |
Remarks
This method will automatically unregister the SendEventBatchSucceededAsync and SendEventBatchFailedAsync handlers.
DisposeAsync()
Closes the producer and performs the tasks needed to clean up all the resources used by the EventHubBufferedProducerClient.
Declaration
[System.Diagnostics.DebuggerStepThrough]
public virtual System.Threading.Tasks.ValueTask DisposeAsync ();
Returns
System.Threading.Tasks.ValueTask
A task to be resolved on when the operation has completed. |
Remarks
Calling this method will also invoke Azure.Messaging.EventHubs.Producer.EventHubBufferedProducerClient.FlushInternalAsync(System.Threading.CancellationToken), which will attempt to publish any events that are still pending, and finish any active sending. It will also automatically unregister the SendEventBatchSucceededAsync and SendEventBatchFailedAsync handlers.
This method is identical to CloseAsync(Boolean, CancellationToken) and either can be used to send pending events and clean up resources.
EnqueueEventAsync(EventData, CancellationToken)
Enqueues an EventData into the buffer to be published to the Event Hub. If there is no capacity in
the buffer when this method is invoked, it will wait for space to become available and ensure that the eventData
has been enqueued.
When this call returns, the eventData
has been accepted into the buffer, but it may not have been published yet.
Publishing will take place at a nondeterministic point in the future as the buffer is processed.
Declaration
public virtual System.Threading.Tasks.Task<int> EnqueueEventAsync (Azure.Messaging.EventHubs.EventData eventData, System.Threading.CancellationToken cancellationToken = null);
Parameters
EventData
eventData
The event to be enqueued into the buffer and, later, published. |
System.Threading.CancellationToken
cancellationToken
An optional System.Threading.CancellationToken instance to signal the request to cancel the operation. |
Returns
System.Threading.Tasks.Task<System.Int32>
The total number of events that are currently buffered and waiting to be published, across all partitions. |
Remarks
Upon the first attempt to enqueue an event, the SendEventBatchSucceededAsync and SendEventBatchFailedAsync handlers can no longer be changed.
Exceptions
System.InvalidOperationException
Occurs when no SendEventBatchFailedAsync handler is currently registered. |
EventHubsException
Occurs when querying Event Hub metadata took longer than expected. |
EnqueueEventAsync(EventData, EnqueueEventOptions, CancellationToken)
Enqueues an EventData into the buffer to be published to the Event Hub. If there is no capacity in
the buffer when this method is invoked, it will wait for space to become available and ensure that the eventData
has been enqueued.
When this call returns, the eventData
has been accepted into the buffer, but it may not have been published yet.
Publishing will take place at a nondeterministic point in the future as the buffer is processed.
Declaration
[System.Diagnostics.DebuggerStepThrough]
public virtual System.Threading.Tasks.Task<int> EnqueueEventAsync (Azure.Messaging.EventHubs.EventData eventData, Azure.Messaging.EventHubs.Producer.EnqueueEventOptions options, System.Threading.CancellationToken cancellationToken = null);
Parameters
EventData
eventData
The event to be enqueued into the buffer and, later, published. |
EnqueueEventOptions
options
The set of options to apply when publishing this event. |
System.Threading.CancellationToken
cancellationToken
An optional System.Threading.CancellationToken instance to signal the request to cancel the operation. |
Returns
System.Threading.Tasks.Task<System.Int32>
The total number of events that are currently buffered and waiting to be published, across all partitions. |
Remarks
Upon the first attempt to enqueue an event, the SendEventBatchSucceededAsync and SendEventBatchFailedAsync handlers can no longer be changed.
Exceptions
System.InvalidOperationException
Occurs when an invalid partition identifier has been specified in the |
EventHubsException
Occurs when querying Event Hub metadata took longer than expected. |
EnqueueEventsAsync(IEnumerable<EventData>, CancellationToken)
Enqueues a set of EventData into the buffer to be published to the Event Hub. If there is insufficient capacity in
the buffer when this method is invoked, it will wait for space to become available and ensure that all events
in the events
set have been enqueued.
When this call returns, the events
have been accepted into the buffer, but it may not have been published yet.
Publishing will take place at a nondeterministic point in the future as the buffer is processed.
Declaration
public virtual System.Threading.Tasks.Task<int> EnqueueEventsAsync (System.Collections.Generic.IEnumerable<Azure.Messaging.EventHubs.EventData> events, System.Threading.CancellationToken cancellationToken = null);
Parameters
System.Collections.Generic.IEnumerable<EventData>
events
The set of events to be enqueued into the buffer and, later, published. |
System.Threading.CancellationToken
cancellationToken
An optional System.Threading.CancellationToken instance to signal the request to cancel the operation. |
Returns
System.Threading.Tasks.Task<System.Int32>
The total number of events that are currently buffered and waiting to be published, across all partitions. |
Remarks
Should cancellation or an unexpected exception occur, it is possible for calls to this method to result in a partial failure where some, but not all,
of the events
have enqueued. For scenarios where it is important to understand whether each individual event has been
enqueued, it is recommended to call the see EnqueueEventAsync(EventData, EnqueueEventOptions, CancellationToken) or
EnqueueEventAsync(EventData, CancellationToken) overloads instead of this method.
Upon the first attempt to enqueue events, the SendEventBatchSucceededAsync and SendEventBatchFailedAsync handlers can no longer be changed.
Exceptions
System.InvalidOperationException
Occurs when no SendEventBatchFailedAsync handler is currently registered. |
EventHubsException
Occurs when querying Event Hub metadata took longer than expected. |
EnqueueEventsAsync(IEnumerable<EventData>, EnqueueEventOptions, CancellationToken)
Enqueues a set of EventData into the buffer to be published to the Event Hub. If there is insufficient capacity in
the buffer when this method is invoked, it will wait for space to become available and ensure that all events
in the events
set have been enqueued.
When this call returns, the events
have been accepted into the buffer, but it may not have been published yet.
Publishing will take place at a nondeterministic point in the future as the buffer is processed.
Declaration
[System.Diagnostics.DebuggerStepThrough]
public virtual System.Threading.Tasks.Task<int> EnqueueEventsAsync (System.Collections.Generic.IEnumerable<Azure.Messaging.EventHubs.EventData> events, Azure.Messaging.EventHubs.Producer.EnqueueEventOptions options, System.Threading.CancellationToken cancellationToken = null);
Parameters
System.Collections.Generic.IEnumerable<EventData>
events
The set of events to be enqueued into the buffer and, later, published. |
EnqueueEventOptions
options
The set of options to apply when publishing these events. |
System.Threading.CancellationToken
cancellationToken
An optional System.Threading.CancellationToken instance to signal the request to cancel the operation. |
Returns
System.Threading.Tasks.Task<System.Int32>
The total number of events that are currently buffered and waiting to be published, across all partitions. |
Remarks
Should cancellation or an unexpected exception occur, it is possible for calls to this method to result in a partial failure where some, but not all,
of the events
have enqueued. For scenarios where it is important to understand whether each individual event has been
enqueued, it is recommended to call the see EnqueueEventAsync(EventData, EnqueueEventOptions, CancellationToken) or
EnqueueEventAsync(EventData, CancellationToken) overloads instead of this method.
Upon the first attempt to enqueue events, the SendEventBatchSucceededAsync and SendEventBatchFailedAsync handlers can no longer be changed.
Exceptions
System.InvalidOperationException
Occurs when an invalid partition identifier has been specified in the |
EventHubsException
Occurs when the EventHubBufferedProducerClient was unable to start within the configured timeout period. |
Equals(Object)
Determines whether the specified System.Object is equal to this instance.
Declaration
[System.ComponentModel.EditorBrowsable]
public override bool Equals (object obj);
Parameters
System.Object
obj
The System.Object to compare with this instance. |
Returns
System.Boolean
|
FlushAsync(CancellationToken)
Attempts to publish all events in the buffer immediately. This may result in multiple batches being published, the outcome of each of which will be individually reported by the SendEventBatchSucceededAsync and SendEventBatchFailedAsync handlers.
Upon completion of this method, the buffer will be empty.
Declaration
[System.Diagnostics.DebuggerStepThrough]
public virtual System.Threading.Tasks.Task FlushAsync (System.Threading.CancellationToken cancellationToken = null);
Parameters
System.Threading.CancellationToken
cancellationToken
An optional System.Threading.CancellationToken instance to signal the request to cancel the operation. |
Returns
System.Threading.Tasks.Task
|
GetBufferedEventCount(String)
The number of events that are buffered and waiting to be published for a given partition.
Declaration
public virtual int GetBufferedEventCount (string partitionId);
Parameters
System.String
partitionId
The identifier of the partition. |
Returns
System.Int32
|
GetEventHubPropertiesAsync(CancellationToken)
Retrieves information about the Event Hub that the connection is associated with, including the number of partitions present and their identifiers.
Declaration
[System.Diagnostics.DebuggerStepThrough]
public virtual System.Threading.Tasks.Task<Azure.Messaging.EventHubs.EventHubProperties> GetEventHubPropertiesAsync (System.Threading.CancellationToken cancellationToken = null);
Parameters
System.Threading.CancellationToken
cancellationToken
An optional System.Threading.CancellationToken instance to signal the request to cancel the operation. |
Returns
System.Threading.Tasks.Task<EventHubProperties>
The set of information for the Event Hub that this client is associated with. |
GetHashCode()
Returns a hash code for this instance.
Declaration
[System.ComponentModel.EditorBrowsable]
public override int GetHashCode ();
Returns
System.Int32
A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. |
GetPartitionIdsAsync(CancellationToken)
Retrieves the set of identifiers for the partitions of an Event Hub.
Declaration
[System.Diagnostics.DebuggerStepThrough]
public virtual System.Threading.Tasks.Task<string[]> GetPartitionIdsAsync (System.Threading.CancellationToken cancellationToken = null);
Parameters
System.Threading.CancellationToken
cancellationToken
An optional System.Threading.CancellationToken instance to signal the request to cancel the operation. |
Returns
System.Threading.Tasks.Task<System.String[]>
The set of identifiers for the partitions within the Event Hub that this client is associated with. |
Remarks
This method is synonymous with invoking GetEventHubPropertiesAsync(CancellationToken) and reading the PartitionIds property that is returned. It is offered as a convenience for quick access to the set of partition identifiers for the associated Event Hub. No new or extended information is presented.
GetPartitionPropertiesAsync(String, CancellationToken)
Retrieves information about a specific partition for an Event Hub, including elements that describe the available events in the partition event stream.
Declaration
[System.Diagnostics.DebuggerStepThrough]
public virtual System.Threading.Tasks.Task<Azure.Messaging.EventHubs.PartitionProperties> GetPartitionPropertiesAsync (string partitionId, System.Threading.CancellationToken cancellationToken = null);
Parameters
System.String
partitionId
The unique identifier of a partition associated with the Event Hub. |
System.Threading.CancellationToken
cancellationToken
An optional System.Threading.CancellationToken instance to signal the request to cancel the operation. |
Returns
System.Threading.Tasks.Task<PartitionProperties>
The set of information for the requested partition under the Event Hub this client is associated with. |
ListPartitionIdsAsync(EventHubProducerClient, CancellationToken)
Queries for the identifiers of the Event Hub partitions.
Declaration
[System.Diagnostics.DebuggerStepThrough]
protected virtual System.Threading.Tasks.Task<string[]> ListPartitionIdsAsync (Azure.Messaging.EventHubs.Producer.EventHubProducerClient producer, System.Threading.CancellationToken cancellationToken);
Parameters
EventHubProducerClient
producer
The producer client instance to use for querying. |
System.Threading.CancellationToken
cancellationToken
A System.Threading.CancellationToken instance to signal the request to cancel the query. |
Returns
System.Threading.Tasks.Task<System.String[]>
The set of identifiers for the Event Hub partitions. |
OnSendFailedAsync(IReadOnlyList<EventData>, Exception, String, CancellationToken)
Responsible for raising the SendEventBatchFailedAsync event upon the failed publishing of a batch of events, after all eligible retries are exhausted.
Declaration
[System.Diagnostics.DebuggerStepThrough]
protected virtual System.Threading.Tasks.Task OnSendFailedAsync (System.Collections.Generic.IReadOnlyList<Azure.Messaging.EventHubs.EventData> events, Exception exception, string partitionId, System.Threading.CancellationToken cancellationToken = null);
Parameters
System.Collections.Generic.IReadOnlyList<EventData>
events
The set of events belonging to the batch that failed to be published. |
System.Exception
exception
The System.Exception that was raised when the events failed to publish. |
System.String
partitionId
The identifier of the partition that the batch of events was published to. |
System.Threading.CancellationToken
cancellationToken
A System.Threading.CancellationToken instance to signal the request to cancel publishing. |
Returns
System.Threading.Tasks.Task
|
OnSendSucceededAsync(IReadOnlyList<EventData>, String, CancellationToken)
Responsible for raising the SendEventBatchSucceededAsync event upon the successful publishing of a batch of events.
Declaration
[System.Diagnostics.DebuggerStepThrough]
protected virtual System.Threading.Tasks.Task OnSendSucceededAsync (System.Collections.Generic.IReadOnlyList<Azure.Messaging.EventHubs.EventData> events, string partitionId, System.Threading.CancellationToken cancellationToken = null);
Parameters
System.Collections.Generic.IReadOnlyList<EventData>
events
The set of events belonging to the batch that was successfully published. |
System.String
partitionId
The identifier of the partition that the batch of events was published to. |
System.Threading.CancellationToken
cancellationToken
A System.Threading.CancellationToken instance to signal the request to cancel publishing. |
Returns
System.Threading.Tasks.Task
|
ToString()
Converts the instance to string representation.
Declaration
[System.ComponentModel.EditorBrowsable]
public override string ToString ();
Returns
System.String
A System.String that represents this instance. |
Events
SendEventBatchFailedAsync
Invoked for any batch of events that failed to be published to the Event Hub, this handler must be provided before events may be enqueued. If this producer was not configured with MaximumConcurrentSends and MaximumConcurrentSendsPerPartition both set to 1, the handler will be invoked concurrently.
It is safe to attempt resending the events by calling EnqueueEventAsync(EventData, EnqueueEventOptions, CancellationToken) or EnqueueEventsAsync(IEnumerable<EventData>, EnqueueEventOptions, CancellationToken) from within this handler. It is important to note that doing so will place them at the end of the buffer; the original order will not be maintained.
This handler will be awaited after failure to publish the batch; the publishing operation is not considered complete until the handler call returns. It is advised that no long-running operations be performed in the handler to avoid negatively impacting throughput.
It is not recommended to invoke CloseAsync(Boolean, CancellationToken) or DisposeAsync() from this handler; doing so may result in a deadlock scenario if those calls are awaited.
Declaration
public event Func<Azure.Messaging.EventHubs.Producer.SendEventBatchFailedEventArgs,System.Threading.Tasks.Task> SendEventBatchFailedAsync;
Remarks
Should a transient failure occur during publishing, this handler will not be invoked immediately; it is only invoked after applying the retry policy and all eligible retries have been exhausted. Should publishing succeed during a retry attempt, this handler is not invoked.
Since applications do not have deterministic control over failed batches, it is recommended that the application set a generous number of retries and try timeout interval in the RetryOptions. Doing so will allow the EventHubBufferedProducerClient a higher chance to recover from transient failures. This is especially important when ensuring the order of events is needed.
It is not necessary to explicitly unregister this handler; it will be automatically unregistered when CloseAsync(Boolean, CancellationToken) or DisposeAsync() is invoked.
Exceptions
System.ArgumentException
If an attempt is made to remove a handler that doesn't match the current handler registered. |
System.NotSupportedException
If an attempt is made to add a handler when one is currently registered. |
See Also
SendEventBatchSucceededAsync
Invoked after each batch of events has been successfully published to the Event Hub, this handler is optional and is intended to provide notifications for interested listeners. If this producer was configured with MaximumConcurrentSends or MaximumConcurrentSendsPerPartition set greater than 1, the handler will be invoked concurrently.
This handler will be awaited after publishing the batch; the publishing operation will not be considered complete until the handler call returns. It is advised that no long-running operations be performed in the handler to avoid negatively impacting throughput.
It is not recommended to invoke CloseAsync(Boolean, CancellationToken) or DisposeAsync() from this handler; doing so may result in a deadlock scenario if those calls are awaited.
Declaration
public event Func<Azure.Messaging.EventHubs.Producer.SendEventBatchSucceededEventArgs,System.Threading.Tasks.Task> SendEventBatchSucceededAsync;
Remarks
It is not necessary to explicitly unregister this handler; it will be automatically unregistered when CloseAsync(Boolean, CancellationToken) or DisposeAsync() is invoked.
Exceptions
System.ArgumentException
If an attempt is made to remove a handler that doesn't match the current handler registered. |
System.NotSupportedException
If an attempt is made to add a handler when one is currently registered. |