Class EventHubBufferedProducerClientBuilder
- All Implemented Interfaces:
com.azure.core.amqp.client.traits.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>
EventHubBufferedProducerClient
and EventHubBufferedProducerAsyncClient
.
To create an instance of EventHubBufferedProducerClient
or EventHubBufferedProducerAsyncClient
, the
following fields are required:
onSendBatchSucceeded(Consumer)
- A callback when events are successfully published to Event Hubs.onSendBatchFailed(Consumer)
- 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:
connectionString(String)
with a connection string to a specific Event Hub.connectionString(String, String)
with an Event Hub namespace connection string and the Event Hub name.credential(String, String, TokenCredential)
with the fully qualified namespace, Event Hub name, and a set of credentials authorized to use the Event Hub.credential(TokenCredential)
,credential(AzureSasCredential)
, orcredential(AzureNamedKeyCredential)
along withfullyQualifiedNamespace(String)
andeventHubName(String)
. The fully qualified namespace, Event Hub name, and authorized credentials to use the Event Hub.
Creating an EventHubBufferedProducerAsyncClient
TokenCredential credential = new DefaultAzureCredentialBuilder().build(); EventHubBufferedProducerAsyncClient client = new EventHubBufferedProducerClientBuilder() .credential("fully-qualifed-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();
Creating an EventHubBufferedProducerClient
TokenCredential credential = new DefaultAzureCredentialBuilder().build(); EventHubBufferedProducerClient client = new EventHubBufferedProducerClientBuilder() .connectionString("event-hub-namespace-connection-string", "event-hub-name") .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
ConstructorDescriptionCreates a new instance with the following defaults:maxEventBufferLengthPerPartition(int)
is 1500transportType(AmqpTransportType)
isAmqpTransportType.AMQP
maxConcurrentSendsPerPartition(int)
is 1maxConcurrentSends(int)
is 1maxWaitTime(Duration)
is 30 seconds -
Method Summary
Modifier and TypeMethodDescriptionBuilds a new instance of the async buffered producer client.Builds a new instance of the buffered producer client.clientOptions
(com.azure.core.util.ClientOptions clientOptions) Sets the client options.configuration
(com.azure.core.util.Configuration configuration) Sets the configuration store that is used during construction of the service client.connectionString
(String connectionString) Sets the credential information given a connection string to the Event Hub instance.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.credential
(com.azure.core.credential.AzureNamedKeyCredential credential) Sets the credential information for which Event Hub instance to connect to, and how to authorize against it.credential
(com.azure.core.credential.AzureSasCredential credential) Sets the credential information for which Event Hub instance to connect to, and how to authorize against it.credential
(com.azure.core.credential.TokenCredential credential) Sets theTokenCredential
used to authorize requests sent to the service.credential
(String fullyQualifiedNamespace, String eventHubName, com.azure.core.credential.AzureNamedKeyCredential credential) Sets theTokenCredential
used to authorize requests sent to the service.credential
(String fullyQualifiedNamespace, String eventHubName, com.azure.core.credential.AzureSasCredential credential) Sets theTokenCredential
used to authorize requests sent to the service.credential
(String fullyQualifiedNamespace, String eventHubName, com.azure.core.credential.TokenCredential credential) Sets the credential information for which Event Hub instance to connect to, and how to authorize against it.customEndpointAddress
(String customEndpointAddress) Sets a custom endpoint address when connecting to the Event Hubs service.eventHubName
(String eventHubName) Sets the name of the Event Hub to connect the client to.fullyQualifiedNamespace
(String fullyQualifiedNamespace) Sets the fully qualified name for the Event Hubs namespace.maxEventBufferLengthPerPartition
(int maxEventBufferLengthPerPartition) The total number of events that can be buffered for publishing at a given time for a given partition.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.onSendBatchFailed
(Consumer<SendBatchFailedContext> sendFailedContext) The callback to invoke when publishing a set of events fails.onSendBatchSucceeded
(Consumer<SendBatchSucceededContext> sendSucceededContext) The callback to invoke when publishing a set of events succeeds.proxyOptions
(com.azure.core.amqp.ProxyOptions proxyOptions) Sets the proxy configuration to use for the buffered producer.retryOptions
(com.azure.core.amqp.AmqpRetryOptions retryOptions) Sets the retry policy for the producer client.transportType
(com.azure.core.amqp.AmqpTransportType transport) Sets the transport type by which all the communication with Azure Event Hubs occurs.
-
Constructor Details
-
EventHubBufferedProducerClientBuilder
public EventHubBufferedProducerClientBuilder()Creates a new instance with the following defaults:maxEventBufferLengthPerPartition(int)
is 1500transportType(AmqpTransportType)
isAmqpTransportType.AMQP
maxConcurrentSendsPerPartition(int)
is 1maxConcurrentSends(int)
is 1maxWaitTime(Duration)
is 30 seconds
-
-
Method Details
-
clientOptions
public EventHubBufferedProducerClientBuilder clientOptions(com.azure.core.util.ClientOptions clientOptions) Sets the client options.- Specified by:
clientOptions
in interfacecom.azure.core.amqp.client.traits.AmqpTrait<EventHubBufferedProducerClientBuilder>
- Parameters:
clientOptions
- The client options.- Returns:
- The updated
EventHubBufferedProducerClientBuilder
object.
-
configuration
public EventHubBufferedProducerClientBuilder configuration(com.azure.core.util.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. UseConfiguration.NONE
to bypass using configuration settings during construction.- Specified by:
configuration
in interfacecom.azure.core.client.traits.ConfigurationTrait<EventHubBufferedProducerClientBuilder>
- Parameters:
configuration
- The configuration store used to configure the buffered producer.- Returns:
- The updated
EventHubBufferedProducerClientBuilder
object.
-
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.
- Specified by:
connectionString
in interfacecom.azure.core.client.traits.ConnectionStringTrait<EventHubBufferedProducerClientBuilder>
- Parameters:
connectionString
- The connection string to use for connecting to the Event Hub instance. It is expected that the Event Hub name and the shared access key properties are contained in this connection string.- Returns:
- The updated
EventHubBufferedProducerClientBuilder
object. - Throws:
IllegalArgumentException
- ifconnectionString
is null or empty. Or, theconnectionString
does not contain the "EntityPath" key, which is the name of the Event Hub instance.com.azure.core.exception.AzureException
- If the shared access signature token credential could not be created using the connection string.
-
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:
connectionString
- The connection string to use for connecting to the Event Hubs namespace; it is expected that the shared access key properties are contained in this connection string, but not the Event Hub name.eventHubName
- The name of the Event Hub to connect the client to.- Returns:
- The updated
EventHubBufferedProducerClientBuilder
object. - Throws:
NullPointerException
- ifconnectionString
oreventHubName
is null.IllegalArgumentException
- ifconnectionString
oreventHubName
is an empty string. Or, if theconnectionString
contains the Event Hub name.com.azure.core.exception.AzureException
- If the shared access signature token credential could not be created using the connection string.
-
credential
public EventHubBufferedProducerClientBuilder credential(String fullyQualifiedNamespace, String eventHubName, com.azure.core.credential.TokenCredential credential) Sets the credential information for which Event Hub instance to connect to, and how to authorize against it.- Parameters:
fullyQualifiedNamespace
- The fully qualified name for the Event Hubs namespace. This is likely to be similar to "{your-namespace}.servicebus.windows.net".eventHubName
- The name of the Event Hub to connect the client to.credential
- The token credential to use for authorization. Access controls may be specified by the Event Hubs namespace or the requested Event Hub, depending on Azure configuration.- Returns:
- The updated
EventHubBufferedProducerClientBuilder
object. - Throws:
IllegalArgumentException
- iffullyQualifiedNamespace
oreventHubName
is an empty string.NullPointerException
- iffullyQualifiedNamespace
,eventHubName
, orcredential
is null.
-
credential
public EventHubBufferedProducerClientBuilder credential(String fullyQualifiedNamespace, String eventHubName, com.azure.core.credential.AzureNamedKeyCredential credential) Sets theTokenCredential
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 theTokenCredential
type.- Parameters:
fullyQualifiedNamespace
- The fully qualified name for the Event Hubs namespace. This is likely to be similar to "{your-namespace}.servicebus.windows.net".eventHubName
- The name of the Event Hub to connect the client to.credential
- The token credential to use for authorization. Access controls may be specified by the Event Hubs namespace or the requested Event Hub, depending on Azure configuration.- Returns:
- The updated
EventHubBufferedProducerClientBuilder
object. - Throws:
NullPointerException
- iffullyQualifiedNamespace
,eventHubName
, orcredential
is null.
-
credential
public EventHubBufferedProducerClientBuilder credential(String fullyQualifiedNamespace, String eventHubName, com.azure.core.credential.AzureSasCredential credential) Sets theTokenCredential
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 theTokenCredential
type.- Parameters:
fullyQualifiedNamespace
- The fully qualified name for the Event Hubs namespace. This is likely to be similar to "{your-namespace}.servicebus.windows.net".eventHubName
- The name of the Event Hub to connect the client to.credential
- The token credential to use for authorization. Access controls may be specified by the Event Hubs namespace or the requested Event Hub, depending on Azure configuration.- Returns:
- The updated
EventHubBufferedProducerClientBuilder
object. - Throws:
NullPointerException
- iffullyQualifiedNamespace
,eventHubName
, orcredential
is null.
-
credential
public EventHubBufferedProducerClientBuilder credential(com.azure.core.credential.AzureNamedKeyCredential credential) Sets the credential information for which Event Hub instance to connect to, and how to authorize against it.- Specified by:
credential
in interfacecom.azure.core.client.traits.AzureNamedKeyCredentialTrait<EventHubBufferedProducerClientBuilder>
- Parameters:
credential
- The shared access name and 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.- Returns:
- The updated
EventHubBufferedProducerClientBuilder
object. - Throws:
NullPointerException
- ifcredentials
is null.
-
credential
public EventHubBufferedProducerClientBuilder credential(com.azure.core.credential.AzureSasCredential credential) Sets the credential information for which Event Hub instance to connect to, and how to authorize against it.- Specified by:
credential
in interfacecom.azure.core.client.traits.AzureSasCredentialTrait<EventHubBufferedProducerClientBuilder>
- Parameters:
credential
- The shared access signature credential to use for authorization. Access controls may be specified by the Event Hubs namespace or the requested Event Hub, depending on Azure configuration.- Returns:
- The updated
EventHubBufferedProducerClientBuilder
object. - Throws:
NullPointerException
- ifcredentials
is null.
-
credential
public EventHubBufferedProducerClientBuilder credential(com.azure.core.credential.TokenCredential credential) Sets theTokenCredential
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 theTokenCredential
type.- Specified by:
credential
in interfacecom.azure.core.client.traits.TokenCredentialTrait<EventHubBufferedProducerClientBuilder>
- Parameters:
credential
- The token credential to use for authorization. Access controls may be specified by the Event Hubs namespace or the requested Event Hub, depending on Azure configuration.- Returns:
- The updated
EventHubBufferedProducerClientBuilder
object. - Throws:
NullPointerException
- ifcredentials
is null.
-
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
transport type
is used.- Parameters:
customEndpointAddress
- The custom endpoint address.- Returns:
- The updated
EventHubBufferedProducerClientBuilder
object. - Throws:
IllegalArgumentException
- ifcustomEndpointAddress
cannot be parsed into a validURL
.
-
fullyQualifiedNamespace
public EventHubBufferedProducerClientBuilder fullyQualifiedNamespace(String fullyQualifiedNamespace) Sets the fully qualified name for the Event Hubs namespace.- Parameters:
fullyQualifiedNamespace
- The fully qualified name for the Event Hubs namespace. This is likely to be similar to "{your-namespace}.servicebus.windows.net".- Returns:
- The updated object.
- Throws:
IllegalArgumentException
- iffullyQualifiedNamespace
is an empty string.NullPointerException
- iffullyQualifiedNamespace
is null.
-
eventHubName
Sets the name of the Event Hub to connect the client to.- Parameters:
eventHubName
- The name of the Event Hub to connect the client to.- Returns:
- The updated object.
- Throws:
IllegalArgumentException
- ifeventHubName
is an empty string.NullPointerException
- ifeventHubName
is null.
-
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 theenqueueEvent
methods on eitherEventHubBufferedProducerClient
orEventHubBufferedProducerAsyncClient
. The default limit is 1500 queued events for each partition.- Parameters:
maxEventBufferLengthPerPartition
- Total number of events that can be buffered for publishing at a given time.- Returns:
- The updated
EventHubBufferedProducerClientBuilder
object.
-
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:
maxWaitTime
- The amount of time to wait.- Returns:
- The updated
EventHubBufferedProducerClientBuilder
object.
-
onSendBatchFailed
public EventHubBufferedProducerClientBuilder onSendBatchFailed(Consumer<SendBatchFailedContext> sendFailedContext) The callback to invoke when publishing a set of events fails.- Parameters:
sendFailedContext
- The callback to invoke.- Returns:
- The updated
EventHubBufferedProducerClientBuilder
object.
-
onSendBatchSucceeded
public EventHubBufferedProducerClientBuilder onSendBatchSucceeded(Consumer<SendBatchSucceededContext> sendSucceededContext) The callback to invoke when publishing a set of events succeeds.- Parameters:
sendSucceededContext
- The callback to invoke when publishing a ste of events succeeds.- Returns:
- The updated
EventHubBufferedProducerClientBuilder
object.
-
proxyOptions
public EventHubBufferedProducerClientBuilder proxyOptions(com.azure.core.amqp.ProxyOptions proxyOptions) Sets the proxy configuration to use for the buffered producer. When a proxy is configured,AmqpTransportType.AMQP_WEB_SOCKETS
must be used for the transport type.- Specified by:
proxyOptions
in interfacecom.azure.core.amqp.client.traits.AmqpTrait<EventHubBufferedProducerClientBuilder>
- Parameters:
proxyOptions
- The proxy configuration to use.- Returns:
- The updated
EventHubBufferedProducerClientBuilder
object.
-
retryOptions
public EventHubBufferedProducerClientBuilder retryOptions(com.azure.core.amqp.AmqpRetryOptions retryOptions) Sets the retry policy for the producer client. If not specified, the default retry options are used.- Specified by:
retryOptions
in interfacecom.azure.core.amqp.client.traits.AmqpTrait<EventHubBufferedProducerClientBuilder>
- Parameters:
retryOptions
- The retry policy to use.- Returns:
- The updated
EventHubBufferedProducerClientBuilder
object.
-
transportType
public EventHubBufferedProducerClientBuilder transportType(com.azure.core.amqp.AmqpTransportType transport) Sets the transport type by which all the communication with Azure Event Hubs occurs. Default value isAmqpTransportType.AMQP
.- Specified by:
transportType
in interfacecom.azure.core.amqp.client.traits.AmqpTrait<EventHubBufferedProducerClientBuilder>
- Parameters:
transport
- The transport type to use.- Returns:
- The updated
EventHubBufferedProducerClientBuilder
object.
-
buildAsyncClient
Builds a new instance of the async buffered producer client.- Returns:
- A new instance of
EventHubBufferedProducerAsyncClient
. - Throws:
NullPointerException
- ifonSendBatchSucceeded(Consumer)
,onSendBatchFailed(Consumer)
, ormaxWaitTime(Duration)
are null.IllegalArgumentException
- ifmaxConcurrentSends(int)
,maxConcurrentSendsPerPartition(int)
, ormaxEventBufferLengthPerPartition(int)
are less than 1.
-
buildClient
Builds a new instance of the buffered producer client.- Returns:
- A new instance of
EventHubBufferedProducerClient
.
-