ServiceBusAdministrationClientBuilder Class
- java.
lang. Object - com.
azure. messaging. servicebus. administration. ServiceBusAdministrationClientBuilder
- com.
Implements
public final class ServiceBusAdministrationClientBuilder
implements TokenCredentialTrait<ServiceBusAdministrationClientBuilder>, AzureSasCredentialTrait<ServiceBusAdministrationClientBuilder>, ConnectionStringTrait<ServiceBusAdministrationClientBuilder>, HttpTrait<ServiceBusAdministrationClientBuilder>, ConfigurationTrait<ServiceBusAdministrationClientBuilder>, EndpointTrait<ServiceBusAdministrationClientBuilder>
This class provides a fluent builder API to help aid the configuration and instantiation of ServiceBusAdministrationClient and ServiceBusAdministrationAsyncClient. Call buildClient() and buildAsyncClient() respectively to construct an instance of the desired client.
Credentials are required to perform operations against Azure Service Bus. They can be set by using one of the following methods:
- connectionString(String connectionString) with a Service Bus namespace connection string.
- credential(String fullyQualifiedNamespace, TokenCredential credential) with the fully qualified Service Bus namespace and a set of credentials authorized to use the namespace.
- credential(TokenCredential credential) and credential(AzureSasCredential credential) overloads can be used with its respective credentials. In addition, endpoint(String endpoint) must be set.
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: Create the sync client
The following code sample demonstrates the creation of the synchronous administration client.
HttpLogOptions logOptions = new HttpLogOptions()
.setLogLevel(HttpLogDetailLevel.HEADERS);
// DefaultAzureCredential creates a credential based on the environment it is executed in.
TokenCredential tokenCredential = new DefaultAzureCredentialBuilder().build();
// 'fullyQualifiedNamespace' will look similar to "{your-namespace}.servicebus.windows.net"
ServiceBusAdministrationClient client = new ServiceBusAdministrationClientBuilder()
.credential(fullyQualifiedNamespace, tokenCredential)
.httpLogOptions(logOptions)
.buildClient();
Sample: Create the async client using Azure Identity
The follow code sample demonstrates the creation of the async administration client.
// DefaultAzureCredential creates a credential based on the environment it is executed in.
TokenCredential credential = new DefaultAzureCredentialBuilder().build();
// 'fullyQualifiedNamespace' will look similar to "{your-namespace}.servicebus.windows.net"
ServiceBusAdministrationAsyncClient client = new ServiceBusAdministrationClientBuilder()
.credential(fullyQualifiedNamespace, new DefaultAzureCredentialBuilder().build())
.buildAsyncClient();
Sample: Create the async client
The follow code sample demonstrates the creation of the async administration client with retry options and HTTP log options configured.
// DefaultAzureCredential creates a credential based on the environment it is executed in.
TokenCredential credential = new DefaultAzureCredentialBuilder().build();
RetryOptions retryOptions = new RetryOptions(new FixedDelayOptions(4, Duration.ofSeconds(20)));
// "<<fully-qualified-namespace>>" will look similar to "{your-namespace}.servicebus.windows.net"
ServiceBusAdministrationAsyncClient client = new ServiceBusAdministrationClientBuilder()
.credential("<<fully-qualified-namespace>>", credential)
.retryOptions(retryOptions)
.httpLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.HEADERS))
.buildAsyncClient();
Constructor Summary
Constructor | Description |
---|---|
ServiceBusAdministrationClientBuilder() |
Constructs a builder with the default parameters. |
Method Summary
Methods inherited from java.lang.Object
Constructor Details
ServiceBusAdministrationClientBuilder
public ServiceBusAdministrationClientBuilder()
Constructs a builder with the default parameters.
Method Details
addPolicy
public ServiceBusAdministrationClientBuilder addPolicy(HttpPipelinePolicy policy)
Adds a HttpPipelinePolicy to apply on each request sent.
Note: It is important to understand the precedence order of the HttpTrait APIs. In particular, if a HttpPipeline is specified, this takes precedence over all other APIs in the trait, and they will be ignored. If no HttpPipeline is specified, a HTTP pipeline will be constructed internally based on the settings provided to this trait. Additionally, there may be other APIs in types that implement this trait that are also ignored if an HttpPipeline is specified, so please be sure to refer to the documentation of types that implement this trait to understand the full set of implications.
Parameters:
Returns:
buildAsyncClient
public ServiceBusAdministrationAsyncClient buildAsyncClient()
Creates a ServiceBusAdministrationAsyncClient based on options set in the builder. Every time buildAsyncClient
is invoked, a new instance of the client is created.
If pipeline(HttpPipeline pipeline) is set, then the pipeline
and endpoint(String endpoint) are used to create the ServiceBusAdministrationAsyncClient. All other builder settings are ignored.
Returns:
buildClient
public ServiceBusAdministrationClient buildClient()
Creates a ServiceBusAdministrationClient based on options set in the builder. Every time buildClient
is invoked, a new instance of the client is created.
If pipeline(HttpPipeline pipeline) is set, then the pipeline
and endpoint(String endpoint) are used to create the ServiceBusAdministrationClient. All other builder settings are ignored.
Returns:
clientOptions
public ServiceBusAdministrationClientBuilder clientOptions(ClientOptions clientOptions)
Allows for setting common properties such as application ID, headers, proxy configuration, etc. Note that it is recommended that this method be called with an instance of the HttpClientOptions class (a subclass of the ClientOptions base class). The HttpClientOptions subclass provides more configuration options suitable for HTTP clients, which is applicable for any class that implements this HttpTrait interface.
Note: It is important to understand the precedence order of the HttpTrait APIs. In particular, if a HttpPipeline is specified, this takes precedence over all other APIs in the trait, and they will be ignored. If no HttpPipeline is specified, a HTTP pipeline will be constructed internally based on the settings provided to this trait. Additionally, there may be other APIs in types that implement this trait that are also ignored if an HttpPipeline is specified, so please be sure to refer to the documentation of types that implement this trait to understand the full set of implications.
Parameters:
Returns:
configuration
public ServiceBusAdministrationClientBuilder configuration(Configuration configuration)
Sets the configuration store that is used during construction of the service client. The default configuration store is a clone of the global configuration store, use NONE to bypass using configuration settings during construction.
Parameters:
Returns:
connectionString
public ServiceBusAdministrationClientBuilder connectionString(String connectionString)
Sets the connection string for a Service Bus namespace or a specific Service Bus resource.
Parameters:
Returns:
credential
public ServiceBusAdministrationClientBuilder credential(AzureSasCredential credential)
Sets the credential with Shared Access Signature for the Service Bus resource. Refer to Service Bus access control with Shared Access Signatures.
Parameters:
Returns:
credential
public ServiceBusAdministrationClientBuilder 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:
credential
public ServiceBusAdministrationClientBuilder credential(String fullyQualifiedNamespace, TokenCredential credential)
Sets the credential used to authenticate HTTP requests to the Service Bus namespace.
Parameters:
Returns:
endpoint
public ServiceBusAdministrationClientBuilder endpoint(String endpoint)
Sets the service endpoint for the Service Bus namespace.
Parameters:
Returns:
httpClient
public ServiceBusAdministrationClientBuilder httpClient(HttpClient client)
Sets the HttpClient to use for sending and receiving requests to and from the service.
Note: It is important to understand the precedence order of the HttpTrait APIs. In particular, if a HttpPipeline is specified, this takes precedence over all other APIs in the trait, and they will be ignored. If no HttpPipeline is specified, a HTTP pipeline will be constructed internally based on the settings provided to this trait. Additionally, there may be other APIs in types that implement this trait that are also ignored if an HttpPipeline is specified, so please be sure to refer to the documentation of types that implement this trait to understand the full set of implications.
Parameters:
Returns:
httpLogOptions
public ServiceBusAdministrationClientBuilder httpLogOptions(HttpLogOptions logOptions)
Sets the HttpLogOptions to use when sending and receiving requests to and from the service. If a logLevel
is not provided, default value of HttpLogDetailLevel#NONE is set.
Note: It is important to understand the precedence order of the HttpTrait APIs. In particular, if a HttpPipeline is specified, this takes precedence over all other APIs in the trait, and they will be ignored. If no HttpPipeline is specified, a HTTP pipeline will be constructed internally based on the settings provided to this trait. Additionally, there may be other APIs in types that implement this trait that are also ignored if an HttpPipeline is specified, so please be sure to refer to the documentation of types that implement this trait to understand the full set of implications.
Parameters:
Returns:
pipeline
public ServiceBusAdministrationClientBuilder pipeline(HttpPipeline pipeline)
Sets the HttpPipeline to use for the service client.
Note: It is important to understand the precedence order of the HttpTrait APIs. In particular, if a HttpPipeline is specified, this takes precedence over all other APIs in the trait, and they will be ignored. If no HttpPipeline is specified, a HTTP pipeline will be constructed internally based on the settings provided to this trait. Additionally, there may be other APIs in types that implement this trait that are also ignored if an HttpPipeline is specified, so please be sure to refer to the documentation of types that implement this trait to understand the full set of implications.
The endpoint(String endpoint) is not ignored when pipeline
is set.
Parameters:
Returns:
retryOptions
public ServiceBusAdministrationClientBuilder retryOptions(RetryOptions retryOptions)
Sets the RetryOptions for all the requests made through the client.
Note: It is important to understand the precedence order of the HttpTrait APIs. In particular, if a HttpPipeline is specified, this takes precedence over all other APIs in the trait, and they will be ignored. If no HttpPipeline is specified, a HTTP pipeline will be constructed internally based on the settings provided to this trait. Additionally, there may be other APIs in types that implement this trait that are also ignored if an HttpPipeline is specified, so please be sure to refer to the documentation of types that implement this trait to understand the full set of implications.
Setting this is mutually exclusive with using retryPolicy(HttpPipelinePolicy retryPolicy).
Parameters:
Returns:
retryPolicy
public ServiceBusAdministrationClientBuilder retryPolicy(HttpPipelinePolicy retryPolicy)
Sets the HttpPipelinePolicy that is used when each request is sent. The default retry policy will be used if not provided buildAsyncClient() to build ServiceBusAdministrationClient or ServiceBusAdministrationAsyncClient. Setting this is mutually exclusive with using retryOptions(RetryOptions retryOptions).
Parameters:
Returns:
serviceVersion
public ServiceBusAdministrationClientBuilder serviceVersion(ServiceBusServiceVersion serviceVersion)
Sets the ServiceBusServiceVersion that is used. By default getLatest() is used when none is specified.
Parameters:
Returns: