EventHubBufferedProducerClientBuilder Class
- java.
lang. Object - com.
azure. messaging. eventhubs. EventHubBufferedProducerClientBuilder
- com.
Implements
public final class EventHubBufferedProducerClientBuilder
implements TokenCredentialTrait<EventHubBufferedProducerClientBuilder>, AzureNamedKeyCredentialTrait<EventHubBufferedProducerClientBuilder>, ConnectionStringTrait<EventHubBufferedProducerClientBuilder>, AzureSasCredentialTrait<EventHubBufferedProducerClientBuilder>, AmqpTrait<EventHubBufferedProducerClientBuilder>, ConfigurationTrait<EventHubBufferedProducerClientBuilder>
Builder used to instantiate EventHubBufferedProducerClient and EventHubBufferedProducerAsyncClient.
To create an instance of EventHubBufferedProducerClient or EventHubBufferedProducerAsyncClient, the following fields are required:
onSendBatchSucceeded(Consumer<SendBatchSucceededContext> sendSucceededContext) - A callback when events are successfully published to Event Hubs.
onSendBatchFailed(Consumer<SendBatchFailedContext> sendFailedContext) - A callback when a failure publishing to Event Hubs occurs.
Credentials to perform operations against Azure Event Hubs. They can be set by using one of the following methods:
- credential(String fullyQualifiedNamespace, String eventHubName, TokenCredential credential) with the fully qualified namespace, Event Hub name, and a set of credentials authorized to use the Event Hub.
- credential(TokenCredential credential), credential(AzureSasCredential credential), or credential(AzureNamedKeyCredential credential) along with fullyQualifiedNamespace(String fullyQualifiedNamespace) and eventHubName(String eventHubName). The fully qualified namespace, Event Hub name, and authorized credentials to use the Event Hub.
- connectionString(String connectionString) with a connection string to a specific Event Hub.
- connectionString(String connectionString, String eventHubName) with an Event Hub namespace connection string and the Event Hub name.
The credential used in the following samples is DefaultAzureCredential for authentication. It is appropriate for most scenarios, including local development and production environments. Additionally, we recommend using managed identity for authentication in production environments. You can find more information on different ways of authenticating and their corresponding credential types in the Azure Identity documentation".
Sample: Creating an EventHubBufferedProducerAsyncClient
The following code sample demonstrates the creation of the asynchronous client EventHubBufferedProducerAsyncClient. The fullyQualifiedNamespace is the Event Hubs Namespace's host name. It is listed under the "Essentials" panel after navigating to the Event Hubs Namespace via Azure Portal. The credential used is DefaultAzureCredential because it combines commonly used credentials in deployment and development and chooses the credential to used based on its running environment. The producer is set to publish events every 60 seconds with a buffer size of 1500 events for each partition.
TokenCredential credential = new DefaultAzureCredentialBuilder().build();
// "<<fully-qualified-namespace>>" will look similar to "{your-namespace}.servicebus.windows.net"
// "<<event-hub-name>>" will be the name of the Event Hub instance you created inside the Event Hubs namespace.
EventHubBufferedProducerAsyncClient client = new EventHubBufferedProducerClientBuilder()
.credential("fully-qualified-namespace", "event-hub-name", credential)
.onSendBatchSucceeded(succeededContext -> {
System.out.println("Successfully published events to: " + succeededContext.getPartitionId());
})
.onSendBatchFailed(failedContext -> {
System.out.printf("Failed to published events to %s. Error: %s%n",
failedContext.getPartitionId(), failedContext.getThrowable());
})
.maxWaitTime(Duration.ofSeconds(60))
.maxEventBufferLengthPerPartition(1500)
.buildAsyncClient();
Sample: Creating an EventHubBufferedProducerClient
The following code sample demonstrates the creation of the synchronous client EventHubBufferedProducerClient. The fullyQualifiedNamespace is the Event Hubs Namespace's host name. It is listed under the "Essentials" panel after navigating to the Event Hubs Namespace via Azure Portal. The credential used is DefaultAzureCredential because it combines commonly used credentials in deployment and development and chooses the credential to used based on its running environment. The producer is set to publish events every 60 seconds with a buffer size of 1500 events for each partition.
TokenCredential credential = new DefaultAzureCredentialBuilder().build();
// "<<fully-qualified-namespace>>" will look similar to "{your-namespace}.servicebus.windows.net"
// "<<event-hub-name>>" will be the name of the Event Hub instance you created inside the Event Hubs namespace.
EventHubBufferedProducerClient client = new EventHubBufferedProducerClientBuilder()
.credential("fully-qualified-namespace", "event-hub-name", credential)
.onSendBatchSucceeded(succeededContext -> {
System.out.println("Successfully published events to: " + succeededContext.getPartitionId());
})
.onSendBatchFailed(failedContext -> {
System.out.printf("Failed to published events to %s. Error: %s%n",
failedContext.getPartitionId(), failedContext.getThrowable());
})
.buildClient();
Constructor Summary
| Constructor | Description |
|---|---|
| EventHubBufferedProducerClientBuilder() |
Creates a new instance with the following defaults:
|
Method Summary
Methods inherited from java.lang.Object
Constructor Details
EventHubBufferedProducerClientBuilder
public EventHubBufferedProducerClientBuilder()
Creates a new instance with the following defaults:
- maxEventBufferLengthPerPartition(int maxEventBufferLengthPerPartition) is 1500
- transportType(AmqpTransportType transport) is AMQP
- #maxConcurrentSendsPerPartition(int) is 1
- #maxConcurrentSends(int) is 1
- maxWaitTime(Duration maxWaitTime) is 30 seconds
Method Details
buildAsyncClient
public EventHubBufferedProducerAsyncClient buildAsyncClient()
Builds a new instance of the async buffered producer client.
Returns:
buildClient
public EventHubBufferedProducerClient buildClient()
Builds a new instance of the buffered producer client.
Returns:
clientOptions
public EventHubBufferedProducerClientBuilder clientOptions(ClientOptions clientOptions)
Sets the client options.
Parameters:
Returns:
configuration
public EventHubBufferedProducerClientBuilder configuration(Configuration configuration)
Sets the configuration store that is used during construction of the service client. If not specified, the default configuration store is used to configure the buffered producer. Use NONE to bypass using configuration settings during construction.
Parameters:
Returns:
connectionString
public EventHubBufferedProducerClientBuilder connectionString(String connectionString)
Sets the credential information given a connection string to the Event Hub instance.
If the connection string is copied from the Event Hubs namespace, it will likely not contain the name to 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.
Parameters:
Returns:
connectionString
public EventHubBufferedProducerClientBuilder connectionString(String connectionString, String eventHubName)
Sets the credential information given a connection string to the Event Hubs namespace and name to a specific Event Hub instance.
Parameters:
Returns:
credential
public EventHubBufferedProducerClientBuilder credential(AzureNamedKeyCredential credential)
Sets the credential information for which Event Hub instance to connect to, and how to authorize against it.
Parameters:
Returns:
credential
public EventHubBufferedProducerClientBuilder credential(AzureSasCredential credential)
Sets the credential information for which Event Hub instance to connect to, and how to authorize against it.
Parameters:
Returns:
credential
public EventHubBufferedProducerClientBuilder credential(String fullyQualifiedNamespace, String eventHubName, AzureNamedKeyCredential credential)
Sets the TokenCredential used to authorize requests sent to the service. Refer to the Azure SDK for Java identity and authentication documentation for more details on proper usage of the TokenCredential type.
Parameters:
Returns:
credential
public EventHubBufferedProducerClientBuilder credential(String fullyQualifiedNamespace, String eventHubName, AzureSasCredential credential)
Sets the TokenCredential used to authorize requests sent to the service. Refer to the Azure SDK for Java identity and authentication documentation for more details on proper usage of the TokenCredential type.
Parameters:
Returns:
credential
public EventHubBufferedProducerClientBuilder credential(String fullyQualifiedNamespace, String eventHubName, TokenCredential credential)
Sets the credential information for which Event Hub instance to connect to, and how to authorize against it.
Parameters:
Returns:
credential
public EventHubBufferedProducerClientBuilder credential(TokenCredential credential)
Sets the TokenCredential used to authorize requests sent to the service. Refer to the Azure SDK for Java identity and authentication documentation for more details on proper usage of the TokenCredential type.
Parameters:
Returns:
customEndpointAddress
public EventHubBufferedProducerClientBuilder customEndpointAddress(String customEndpointAddress)
Sets a custom endpoint address when connecting to the Event Hubs service. This can be useful when your network does not allow connecting to the standard Azure Event Hubs endpoint address, but does allow connecting through an intermediary. For example: https://my.custom.endpoint.com:55300.
If no port is specified, the default port for the transportType(AmqpTransportType transport) is used.
Parameters:
Returns:
eventHubName
public EventHubBufferedProducerClientBuilder eventHubName(String eventHubName)
Sets the name of the Event Hub to connect the client to.
Parameters:
Returns:
fullyQualifiedNamespace
public EventHubBufferedProducerClientBuilder fullyQualifiedNamespace(String fullyQualifiedNamespace)
Sets the fully qualified name for the Event Hubs namespace.
Parameters:
Returns:
maxEventBufferLengthPerPartition
public EventHubBufferedProducerClientBuilder maxEventBufferLengthPerPartition(int maxEventBufferLengthPerPartition)
The total number of events that can be buffered for publishing at a given time for a given partition. Once this capacity is reached, more events can enqueued by calling the enqueueEvent methods on either EventHubBufferedProducerClient or EventHubBufferedProducerAsyncClient. The default limit is 1500 queued events for each partition.
Parameters:
Returns:
maxWaitTime
public EventHubBufferedProducerClientBuilder maxWaitTime(Duration maxWaitTime)
The amount of time to wait for a batch to be built with events in the buffer before publishing a partially full batch.
Parameters:
Returns:
onSendBatchFailed
public EventHubBufferedProducerClientBuilder onSendBatchFailed(Consumer<SendBatchFailedContext> sendFailedContext)
The callback to invoke when publishing a set of events fails.
Parameters:
Returns:
onSendBatchSucceeded
public EventHubBufferedProducerClientBuilder onSendBatchSucceeded(Consumer<SendBatchSucceededContext> sendSucceededContext)
The callback to invoke when publishing a set of events succeeds.
Parameters:
Returns:
proxyOptions
public EventHubBufferedProducerClientBuilder proxyOptions(ProxyOptions proxyOptions)
Sets the proxy configuration to use for the buffered producer. When a proxy is configured, AMQP_WEB_SOCKETS must be used for the transport type.
Parameters:
Returns:
retryOptions
public EventHubBufferedProducerClientBuilder retryOptions(AmqpRetryOptions retryOptions)
Sets the retry policy for the producer client. If not specified, the default retry options are used.
Parameters:
Returns:
transportType
public EventHubBufferedProducerClientBuilder transportType(AmqpTransportType transport)
Sets the transport type by which all the communication with Azure Event Hubs occurs. Default value is AMQP.
Parameters:
Returns: