共用方式為


ServiceBusAdministrationClientBuilder Class

  • java.lang.Object
    • com.azure.messaging.servicebus.administration.ServiceBusAdministrationClientBuilder

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:

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

Modifier and Type Method and Description
ServiceBusAdministrationClientBuilder addPolicy(HttpPipelinePolicy policy)

Adds a HttpPipelinePolicy to apply on each request sent.

ServiceBusAdministrationAsyncClient buildAsyncClient()

Creates a ServiceBusAdministrationAsyncClient based on options set in the builder.

ServiceBusAdministrationClient buildClient()

Creates a ServiceBusAdministrationClient based on options set in the builder.

ServiceBusAdministrationClientBuilder clientOptions(ClientOptions clientOptions)

Allows for setting common properties such as application ID, headers, proxy configuration, etc.

ServiceBusAdministrationClientBuilder configuration(Configuration configuration)

Sets the configuration store that is used during construction of the service client.

ServiceBusAdministrationClientBuilder connectionString(String connectionString)

Sets the connection string for a Service Bus namespace or a specific Service Bus resource.

ServiceBusAdministrationClientBuilder credential(AzureSasCredential credential)

Sets the credential with Shared Access Signature for the Service Bus resource.

ServiceBusAdministrationClientBuilder credential(TokenCredential credential)

Sets the TokenCredential used to authorize requests sent to the service.

ServiceBusAdministrationClientBuilder credential(String fullyQualifiedNamespace, TokenCredential credential)

Sets the credential used to authenticate HTTP requests to the Service Bus namespace.

ServiceBusAdministrationClientBuilder endpoint(String endpoint)

Sets the service endpoint for the Service Bus namespace.

ServiceBusAdministrationClientBuilder httpClient(HttpClient client)

Sets the HttpClient to use for sending and receiving requests to and from the service.

ServiceBusAdministrationClientBuilder httpLogOptions(HttpLogOptions logOptions)

Sets the HttpLogOptions to use when sending and receiving requests to and from the service.

ServiceBusAdministrationClientBuilder pipeline(HttpPipeline pipeline)

Sets the HttpPipeline to use for the service client.

ServiceBusAdministrationClientBuilder retryOptions(RetryOptions retryOptions)

Sets the RetryOptions for all the requests made through the client.

ServiceBusAdministrationClientBuilder retryPolicy(HttpPipelinePolicy retryPolicy)

Sets the HttpPipelinePolicy that is used when each request is sent.

ServiceBusAdministrationClientBuilder serviceVersion(ServiceBusServiceVersion serviceVersion)

Sets the ServiceBusServiceVersion that is used.

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:

policy - A HttpPipelinePolicy.

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:

A ServiceBusAdministrationAsyncClient with the options set in the builder.

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:

A ServiceBusAdministrationClient with the options set in the builder.

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:

clientOptions - A configured instance of HttpClientOptions.

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:

configuration - The configuration store used to

Returns:

connectionString

public ServiceBusAdministrationClientBuilder connectionString(String connectionString)

Sets the connection string for a Service Bus namespace or a specific Service Bus resource.

Parameters:

connectionString - Connection string for a Service Bus namespace or a specific Service Bus resource.

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:

credential - AzureSasCredential to be used for authentication.

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:

credential - TokenCredential used to authorize requests sent to the service.

Returns:

credential

public ServiceBusAdministrationClientBuilder credential(String fullyQualifiedNamespace, TokenCredential credential)

Sets the credential used to authenticate HTTP requests to the Service Bus namespace.

Parameters:

fullyQualifiedNamespace - for the Service Bus.
credential - TokenCredential to be used for authentication.

Returns:

endpoint

public ServiceBusAdministrationClientBuilder endpoint(String endpoint)

Sets the service endpoint for the Service Bus namespace.

Parameters:

endpoint - The URL of the Service Bus namespace.

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:

client - The HttpClient to use for requests.

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:

logOptions - The HttpLogOptions to use when sending and receiving requests to and from the service.

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:

pipeline - HttpPipeline to use for sending service requests and receiving responses.

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:

retryOptions - The RetryOptions to use for all the requests made through the client.

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:

retryPolicy - The user's retry policy applied to each request.

Returns:

serviceVersion

public ServiceBusAdministrationClientBuilder serviceVersion(ServiceBusServiceVersion serviceVersion)

Sets the ServiceBusServiceVersion that is used. By default getLatest() is used when none is specified.

Parameters:

serviceVersion - Service version to use.

Returns:

Applies to