Class EventHubBufferedProducerClientBuilder

java.lang.Object
com.azure.messaging.eventhubs.EventHubBufferedProducerClientBuilder
All Implemented Interfaces:
AmqpTrait<EventHubBufferedProducerClientBuilder>, com.azure.core.client.traits.AzureNamedKeyCredentialTrait<EventHubBufferedProducerClientBuilder>, com.azure.core.client.traits.AzureSasCredentialTrait<EventHubBufferedProducerClientBuilder>, com.azure.core.client.traits.ConfigurationTrait<EventHubBufferedProducerClientBuilder>, com.azure.core.client.traits.ConnectionStringTrait<EventHubBufferedProducerClientBuilder>, com.azure.core.client.traits.TokenCredentialTrait<EventHubBufferedProducerClientBuilder>

public final class EventHubBufferedProducerClientBuilder extends Object implements com.azure.core.client.traits.TokenCredentialTrait<EventHubBufferedProducerClientBuilder>, com.azure.core.client.traits.AzureNamedKeyCredentialTrait<EventHubBufferedProducerClientBuilder>, com.azure.core.client.traits.ConnectionStringTrait<EventHubBufferedProducerClientBuilder>, com.azure.core.client.traits.AzureSasCredentialTrait<EventHubBufferedProducerClientBuilder>, AmqpTrait<EventHubBufferedProducerClientBuilder>, com.azure.core.client.traits.ConfigurationTrait<EventHubBufferedProducerClientBuilder>
Builder used to instantiate EventHubBufferedProducerClient and EventHubBufferedProducerAsyncClient.

To create an instance of EventHubBufferedProducerClient or EventHubBufferedProducerAsyncClient, the following fields are required:

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();
 
See Also: