Class ServiceBusAdministrationClientBuilder
- All Implemented Interfaces:
com.azure.core.client.traits.AzureSasCredentialTrait<ServiceBusAdministrationClientBuilder>, com.azure.core.client.traits.ConfigurationTrait<ServiceBusAdministrationClientBuilder>, com.azure.core.client.traits.ConnectionStringTrait<ServiceBusAdministrationClientBuilder>, com.azure.core.client.traits.EndpointTrait<ServiceBusAdministrationClientBuilder>, com.azure.core.client.traits.HttpTrait<ServiceBusAdministrationClientBuilder>, com.azure.core.client.traits.TokenCredentialTrait<ServiceBusAdministrationClientBuilder>
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)with a Service Bus namespace connection string.credential(String, TokenCredential)with the fully qualified Service Bus namespace and a set of credentials authorized to use the namespace.credential(TokenCredential)andcredential(AzureSasCredential)overloads can be used with its respective credentials. In addition,endpoint(String)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();
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs a builder with the default parameters. -
Method Summary
Modifier and TypeMethodDescriptionaddPolicy(com.azure.core.http.policy.HttpPipelinePolicy policy) Adds apipeline policyto apply on each request sent.Creates aServiceBusAdministrationAsyncClientbased on options set in the builder.Creates aServiceBusAdministrationClientbased on options set in the builder.clientOptions(com.azure.core.util.ClientOptions clientOptions) Allows for setting common properties such as application ID, headers, proxy configuration, etc.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 connection string for a Service Bus namespace or a specific Service Bus resource.credential(com.azure.core.credential.AzureSasCredential credential) Sets the credential with Shared Access Signature for the Service Bus resource.credential(com.azure.core.credential.TokenCredential credential) Sets theTokenCredentialused to authorize requests sent to the service.credential(String fullyQualifiedNamespace, com.azure.core.credential.TokenCredential credential) Sets the credential used to authenticate HTTP requests to the Service Bus namespace.Sets the service endpoint for the Service Bus namespace.httpClient(com.azure.core.http.HttpClient client) Sets theHttpClientto use for sending and receiving requests to and from the service.httpLogOptions(com.azure.core.http.policy.HttpLogOptions logOptions) Sets thelogging configurationto use when sending and receiving requests to and from the service.pipeline(com.azure.core.http.HttpPipeline pipeline) Sets theHttpPipelineto use for the service client.retryOptions(com.azure.core.http.policy.RetryOptions retryOptions) Sets theRetryOptionsfor all the requests made through the client.retryPolicy(com.azure.core.http.policy.HttpPipelinePolicy retryPolicy) Sets theHttpPipelinePolicythat is used when each request is sent.serviceVersion(ServiceBusServiceVersion serviceVersion) Sets theServiceBusServiceVersionthat is used.
-
Constructor Details
-
ServiceBusAdministrationClientBuilder
public ServiceBusAdministrationClientBuilder()Constructs a builder with the default parameters.
-
-
Method Details
-
buildAsyncClient
Creates aServiceBusAdministrationAsyncClientbased on options set in the builder. Every timebuildAsyncClientis invoked, a new instance of the client is created.If
pipelineis set, then thepipelineandendpointare used to create theclient. All other builder settings are ignored.- Returns:
- A
ServiceBusAdministrationAsyncClientwith the options set in the builder. - Throws:
NullPointerException- ifendpointhas not been set. This is automatically set whenconnectionStringis set. Explicitly throughendpoint(String), or throughcredential(String, TokenCredential).IllegalStateException- If applicationId if set in bothhttpLogOptionsandclientOptionsand not same.IllegalStateException- If bothretryOptions(RetryOptions)andretryPolicy(HttpPipelinePolicy)have been set.
-
buildClient
Creates aServiceBusAdministrationClientbased on options set in the builder. Every timebuildClientis invoked, a new instance of the client is created.If
pipelineis set, then thepipelineandendpointare used to create theclient. All other builder settings are ignored.- Returns:
- A
ServiceBusAdministrationClientwith the options set in the builder. - Throws:
NullPointerException- ifendpointhas not been set. This is automatically set whenconnectionStringis set. Explicitly throughendpoint(String), or throughcredential(String, TokenCredential).IllegalStateException- If applicationId if set in bothhttpLogOptionsandclientOptionsand not same.IllegalStateException- If bothretryOptions(RetryOptions)andretryPolicy(HttpPipelinePolicy)have been set.
-
addPolicy
public ServiceBusAdministrationClientBuilder addPolicy(com.azure.core.http.policy.HttpPipelinePolicy policy) Adds apipeline policyto apply on each request sent.Note: It is important to understand the precedence order of the HttpTrait APIs. In particular, if a
HttpPipelineis specified, this takes precedence over all other APIs in the trait, and they will be ignored. If noHttpPipelineis 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 anHttpPipelineis specified, so please be sure to refer to the documentation of types that implement this trait to understand the full set of implications.- Specified by:
addPolicyin interfacecom.azure.core.client.traits.HttpTrait<ServiceBusAdministrationClientBuilder>- Parameters:
policy- Apipeline policy.- Returns:
- The updated
ServiceBusAdministrationClientBuilderobject. - Throws:
NullPointerException- Ifpolicyisnull.
-
endpoint
Sets the service endpoint for the Service Bus namespace.- Specified by:
endpointin interfacecom.azure.core.client.traits.EndpointTrait<ServiceBusAdministrationClientBuilder>- Parameters:
endpoint- The URL of the Service Bus namespace.- Returns:
- The updated
ServiceBusAdministrationClientBuilderobject. - Throws:
NullPointerException- ifendpointis null.IllegalArgumentException- ifendpointcannot be parsed into a valid URL.
-
configuration
public ServiceBusAdministrationClientBuilder configuration(com.azure.core.util.Configuration configuration) Sets the configuration store that is used during construction of the service client. The default configuration store is a clone of theglobal configuration store, useConfiguration.NONEto bypass using configuration settings during construction.- Specified by:
configurationin interfacecom.azure.core.client.traits.ConfigurationTrait<ServiceBusAdministrationClientBuilder>- Parameters:
configuration- The configuration store used to- Returns:
- The updated
ServiceBusAdministrationClientBuilderobject.
-
connectionString
Sets the connection string for a Service Bus namespace or a specific Service Bus resource.- Specified by:
connectionStringin interfacecom.azure.core.client.traits.ConnectionStringTrait<ServiceBusAdministrationClientBuilder>- Parameters:
connectionString- Connection string for a Service Bus namespace or a specific Service Bus resource.- Returns:
- The updated
ServiceBusAdministrationClientBuilderobject. - Throws:
NullPointerException- IfconnectionStringisnull.IllegalArgumentException- IfconnectionStringis an entity specific connection string, and not aconnectionStringfor the Service Bus namespace.
-
credential
public ServiceBusAdministrationClientBuilder credential(String fullyQualifiedNamespace, com.azure.core.credential.TokenCredential credential) Sets the credential used to authenticate HTTP requests to the Service Bus namespace.- Parameters:
fullyQualifiedNamespace- for the Service Bus.credential-TokenCredentialto be used for authentication.- Returns:
- The updated
ServiceBusAdministrationClientBuilderobject.
-
credential
public ServiceBusAdministrationClientBuilder credential(com.azure.core.credential.TokenCredential credential) Sets theTokenCredentialused 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 theTokenCredentialtype.- Specified by:
credentialin interfacecom.azure.core.client.traits.TokenCredentialTrait<ServiceBusAdministrationClientBuilder>- Parameters:
credential-TokenCredentialused to authorize requests sent to the service.- Returns:
- The updated
ServiceBusAdministrationClientBuilderobject.
-
credential
public ServiceBusAdministrationClientBuilder credential(com.azure.core.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.- Specified by:
credentialin interfacecom.azure.core.client.traits.AzureSasCredentialTrait<ServiceBusAdministrationClientBuilder>- Parameters:
credential-AzureSasCredentialto be used for authentication.- Returns:
- The updated
ServiceBusAdministrationClientBuilderobject.
-
httpClient
Sets theHttpClientto 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
HttpPipelineis specified, this takes precedence over all other APIs in the trait, and they will be ignored. If noHttpPipelineis 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 anHttpPipelineis specified, so please be sure to refer to the documentation of types that implement this trait to understand the full set of implications.- Specified by:
httpClientin interfacecom.azure.core.client.traits.HttpTrait<ServiceBusAdministrationClientBuilder>- Parameters:
client- TheHttpClientto use for requests.- Returns:
- The updated
ServiceBusAdministrationClientBuilderobject.
-
httpLogOptions
public ServiceBusAdministrationClientBuilder httpLogOptions(com.azure.core.http.policy.HttpLogOptions logOptions) Sets thelogging configurationto use when sending and receiving requests to and from the service. If alogLevelis not provided, default value ofHttpLogDetailLevel.NONEis set.Note: It is important to understand the precedence order of the HttpTrait APIs. In particular, if a
HttpPipelineis specified, this takes precedence over all other APIs in the trait, and they will be ignored. If noHttpPipelineis 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 anHttpPipelineis specified, so please be sure to refer to the documentation of types that implement this trait to understand the full set of implications.- Specified by:
httpLogOptionsin interfacecom.azure.core.client.traits.HttpTrait<ServiceBusAdministrationClientBuilder>- Parameters:
logOptions- Thelogging configurationto use when sending and receiving requests to and from the service.- Returns:
- The updated
ServiceBusAdministrationClientBuilderobject.
-
clientOptions
public ServiceBusAdministrationClientBuilder clientOptions(com.azure.core.util.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 theHttpClientOptionsclass (a subclass of theClientOptionsbase 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
HttpPipelineis specified, this takes precedence over all other APIs in the trait, and they will be ignored. If noHttpPipelineis 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 anHttpPipelineis specified, so please be sure to refer to the documentation of types that implement this trait to understand the full set of implications.- Specified by:
clientOptionsin interfacecom.azure.core.client.traits.HttpTrait<ServiceBusAdministrationClientBuilder>- Parameters:
clientOptions- A configured instance ofHttpClientOptions.- Returns:
- The updated
ServiceBusAdministrationClientBuilderobject. - See Also:
-
pipeline
Sets theHttpPipelineto use for the service client.Note: It is important to understand the precedence order of the HttpTrait APIs. In particular, if a
HttpPipelineis specified, this takes precedence over all other APIs in the trait, and they will be ignored. If noHttpPipelineis 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 anHttpPipelineis specified, so please be sure to refer to the documentation of types that implement this trait to understand the full set of implications.The
endpointis not ignored whenpipelineis set.- Specified by:
pipelinein interfacecom.azure.core.client.traits.HttpTrait<ServiceBusAdministrationClientBuilder>- Parameters:
pipeline-HttpPipelineto use for sending service requests and receiving responses.- Returns:
- The updated
ServiceBusAdministrationClientBuilderobject.
-
retryPolicy
public ServiceBusAdministrationClientBuilder retryPolicy(com.azure.core.http.policy.HttpPipelinePolicy retryPolicy) Sets theHttpPipelinePolicythat is used when each request is sent. The default retry policy will be used if not providedbuildAsyncClient()to buildServiceBusAdministrationClientorServiceBusAdministrationAsyncClient. Setting this is mutually exclusive with usingretryOptions(RetryOptions).- Parameters:
retryPolicy- The user's retry policy applied to each request.- Returns:
- The updated
ServiceBusAdministrationClientBuilderobject.
-
retryOptions
public ServiceBusAdministrationClientBuilder retryOptions(com.azure.core.http.policy.RetryOptions retryOptions) Sets theRetryOptionsfor all the requests made through the client.Note: It is important to understand the precedence order of the HttpTrait APIs. In particular, if a
HttpPipelineis specified, this takes precedence over all other APIs in the trait, and they will be ignored. If noHttpPipelineis 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 anHttpPipelineis 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).- Specified by:
retryOptionsin interfacecom.azure.core.client.traits.HttpTrait<ServiceBusAdministrationClientBuilder>- Parameters:
retryOptions- TheRetryOptionsto use for all the requests made through the client.- Returns:
- The updated
ServiceBusAdministrationClientBuilderobject.
-
serviceVersion
public ServiceBusAdministrationClientBuilder serviceVersion(ServiceBusServiceVersion serviceVersion) Sets theServiceBusServiceVersionthat is used. By defaultServiceBusServiceVersion.getLatest()is used when none is specified.- Parameters:
serviceVersion- Service version to use.- Returns:
- The updated
ServiceBusAdministrationClientBuilderobject.
-