你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn。
QueueServiceClientBuilder 类
- java.
lang. Object - com.
azure. storage. queue. QueueServiceClientBuilder
- com.
实现
public final class QueueServiceClientBuilder
implements TokenCredentialTrait<QueueServiceClientBuilder>, ConnectionStringTrait<QueueServiceClientBuilder>, AzureNamedKeyCredentialTrait<QueueServiceClientBuilder>, AzureSasCredentialTrait<QueueServiceClientBuilder>, HttpTrait<QueueServiceClientBuilder>, ConfigurationTrait<QueueServiceClientBuilder>, EndpointTrait<QueueServiceClientBuilder>
此类提供 Fluent Builder API 来帮助配置和实例化 QueueServiceClient 和 ,调用 buildClient() 将构造 QueueServiceClient 的实例,而调用 buildAsyncClient() 则构造 QueueServiceAsyncClient QueueServiceAsyncClient的实例。
客户端需要 Azure 存储队列服务的终结点、共享名称和授权凭据。 endpoint(String endpoint) 为生成器提供终结点,并可能为生成器提供授权客户端的 SAS 令牌。
使用 SAS 令牌实例化同步队列服务客户端
QueueServiceClient client = new QueueServiceClientBuilder()
.endpoint("https://${accountName}.queue.core.windows.net?${SASToken}")
.buildClient();
使用 SAS 令牌实例化异步队列服务客户端
QueueServiceAsyncClient client = new QueueServiceClientBuilder()
.endpoint("https://{accountName}.queue.core.windows.net?{SASToken}")
.buildAsyncClient();
endpoint
如果 不包含用于构造 SAS 令牌的查询参数,可将sasToken(String sasToken)这些参数与终结点一起使用。
使用 SAS 令牌实例化同步队列服务客户端
QueueServiceAsyncClient client = new QueueServiceClientBuilder()
.endpoint("https://{accountName}.queue.core.windows.net")
.sasToken("{SASTokenQueryParams}")
.buildAsyncClient();
使用 SAS 令牌实例化异步队列服务客户端
QueueServiceAsyncClient client = new QueueServiceClientBuilder()
.endpoint("https://{accountName}.queue.core.windows.net")
.sasToken("{SASTokenQueryParams}")
.buildAsyncClient();
对客户端进行身份验证的另一种方法 StorageSharedKeyCredential是使用 。 若要创建 StorageSharedKeyCredential,必须使用存储队列服务中的连接字符串。 使用 设置 StorageSharedKeyCredential connectionString(String connectionString)。 如果生成器同时具有 SAS 令牌和 StorageSharedKeyCredential,则授权发送到服务的请求时,首选 StorageSharedKeyCredential。
使用连接字符串实例化同步队列服务客户端。
String connectionString = "DefaultEndpointsProtocol=https;AccountName={name};"
+ "AccountKey={key};EndpointSuffix={core.windows.net}";
QueueServiceClient client = new QueueServiceClientBuilder()
.connectionString(connectionString)
.buildClient();
使用连接字符串实例化异步队列服务客户端。
String connectionString = "DefaultEndpointsProtocol=https;AccountName={name};"
+ "AccountKey={key};EndpointSuffix={core.windows.net}";
QueueServiceAsyncClient client = new QueueServiceClientBuilder()
.connectionString(connectionString)
.buildAsyncClient();
构造函数摘要
构造函数 | 说明 |
---|---|
QueueServiceClientBuilder() |
创建能够配置和构造 QueueServiceClient 和 QueueServiceAsyncClient的生成器实例。 |
方法摘要
方法继承自 java.lang.Object
构造函数详细信息
QueueServiceClientBuilder
public QueueServiceClientBuilder()
创建能够配置和构造 QueueServiceClient 和 QueueServiceAsyncClient的生成器实例。
方法详细信息
addPolicy
public QueueServiceClientBuilder addPolicy(HttpPipelinePolicy pipelinePolicy)
添加 要 HttpPipelinePolicy 对发送的每个请求应用。
注意: 了解 HttpTrait API 的优先顺序非常重要。 具体而言,如果 HttpPipeline 指定了 ,则这优先于特征中的所有其他 API,它们将被忽略。 HttpPipeline如果未指定,则根据提供给此特征的设置在内部构造 HTTP 管道。 此外,实现此特征的类型中可能存在其他 API,如果 HttpPipeline 指定 了 ,这些 API 也会被忽略,因此请务必参考实现此特征的类型的文档,以了解完整的一组影响。
Parameters:
Returns:
buildAsyncClient
public QueueServiceAsyncClient buildAsyncClient()
QueueServiceAsyncClient基于生成器中设置的选项创建 。 每次调用时,都会创建 一 QueueServiceAsyncClient 个新的 实例。
如果 pipeline(HttpPipeline httpPipeline) 设置了 ,则 pipeline
使用 和 endpoint(String endpoint) 创建 QueueServiceAsyncClient。 将忽略所有其他生成器设置。
Returns:
buildClient
public QueueServiceClient buildClient()
QueueServiceClient基于生成器中设置的选项创建 。 每次调用时,都会创建 一 QueueServiceClient 个新的 实例。
如果 pipeline(HttpPipeline httpPipeline) 设置了 ,则 pipeline
使用 和 endpoint(String endpoint) 创建 QueueServiceClient。 将忽略所有其他生成器设置。
Returns:
clientOptions
public QueueServiceClientBuilder clientOptions(ClientOptions clientOptions)
允许设置常见属性,例如应用程序 ID、标头、代理配置等。请注意,建议使用类的 HttpClientOptions 实例 (基类的子类 ClientOptions) 调用此方法。 HttpClientOptions 子类提供更多适用于 HTTP 客户端的配置选项,适用于实现此 HttpTrait 接口的任何类。
注意: 了解 HttpTrait API 的优先顺序非常重要。 具体而言,如果 HttpPipeline 指定了 ,则这优先于特征中的所有其他 API,它们将被忽略。 HttpPipeline如果未指定,则根据提供给此特征的设置在内部构造 HTTP 管道。 此外,实现此特征的类型中可能存在其他 API,如果 HttpPipeline 指定 了 ,这些 API 也会被忽略,因此请务必参考实现此特征的类型的文档,以了解完整的一组影响。
Parameters:
Returns:
configuration
public QueueServiceClientBuilder configuration(Configuration configuration)
设置用于在生成客户端期间检索环境配置值的配置对象。
Parameters:
Returns:
connectionString
public QueueServiceClientBuilder connectionString(String connectionString)
设置要连接到服务的连接字符串。
Parameters:
Returns:
credential
public QueueServiceClientBuilder credential(AzureNamedKeyCredential credential)
AzureNamedKeyCredential设置用于授权发送到服务的请求的 。
Parameters:
Returns:
credential
public QueueServiceClientBuilder credential(AzureSasCredential credential)
AzureSasCredential设置用于授权发送到服务的请求的 。
Parameters:
Returns:
credential
public QueueServiceClientBuilder credential(TokenCredential credential)
TokenCredential设置用于授权发送到服务的请求的 。 有关正确使用 TokenCredential 类型的更多详细信息,请参阅 Azure SDK for Java 标识和身份验证文档。
Parameters:
Returns:
credential
public QueueServiceClientBuilder credential(StorageSharedKeyCredential credential)
StorageSharedKeyCredential设置用于授权发送到服务的请求的 。
Parameters:
Returns:
endpoint
public QueueServiceClientBuilder endpoint(String endpoint)
设置客户端将与之交互的 Azure 存储队列实例的终结点。
在尝试生成 SAS 令牌以对发送到服务的请求进行身份验证时,将分析终结点的查询参数。
Parameters:
Returns:
getDefaultHttpLogOptions
public static HttpLogOptions getDefaultHttpLogOptions()
获取默认的存储允许列表日志标头和查询参数。
Returns:
httpClient
public QueueServiceClientBuilder httpClient(HttpClient httpClient)
HttpClient设置用于向/从服务发送和接收请求的 。
注意: 请务必了解 HttpTrait API 的优先顺序。 具体而言,如果 HttpPipeline 指定了 ,则这优先于特征中的所有其他 API,它们将被忽略。 HttpPipeline如果未指定,则将基于提供给此特征的设置在内部构造 HTTP 管道。 此外,实现此特征的类型中可能存在其他 API,如果指定 了 , HttpPipeline 则也会忽略这些 API,因此请务必参考实现此特征的类型的文档以了解完整的含义集。
Parameters:
Returns:
httpLogOptions
public QueueServiceClientBuilder httpLogOptions(HttpLogOptions logOptions)
设置在 HttpLogOptions 向/从服务发送和接收请求时要使用的 。 logLevel
如果未提供 ,则设置 的默认值HttpLogDetailLevel#NONE。
注意: 请务必了解 HttpTrait API 的优先顺序。 具体而言,如果 HttpPipeline 指定了 ,则这优先于特征中的所有其他 API,它们将被忽略。 HttpPipeline如果未指定,则将基于提供给此特征的设置在内部构造 HTTP 管道。 此外,实现此特征的类型中可能存在其他 API,如果指定 了 , HttpPipeline 则也会忽略这些 API,因此请务必参考实现此特征的类型的文档以了解完整的含义集。
Parameters:
Returns:
messageEncoding
public QueueServiceClientBuilder messageEncoding(QueueMessageEncoding messageEncoding)
设置队列消息编码。
Parameters:
Returns:
pipeline
public QueueServiceClientBuilder pipeline(HttpPipeline httpPipeline)
HttpPipeline设置要用于服务客户端的 。
注意: 请务必了解 HttpTrait API 的优先顺序。 具体而言,如果 HttpPipeline 指定了 ,则这优先于特征中的所有其他 API,它们将被忽略。 HttpPipeline如果未指定,则将基于提供给此特征的设置在内部构造 HTTP 管道。 此外,实现此特征的类型中可能存在其他 API,如果指定 了 , HttpPipeline 则也会忽略这些 API,因此请务必参考实现此特征的类型的文档以了解完整的含义集。
endpoint(String endpoint)设置 时pipeline
不会忽略 。
Parameters:
Returns:
processMessageDecodingError
public QueueServiceClientBuilder processMessageDecodingError(Consumer
设置处理程序,该处理程序执行从队列接收消息或达到峰值时所需的任务,但无法解码。
当队列预期是确定 QueueMessageEncoding 的,但有另一个生成者未按预期方式编码消息时,可能会收到此类消息或达到峰值。 即队列包含具有不同编码的消息。
QueueMessageDecodingError 包含 QueueClient 已接收消息 getQueueMessageItem() 的队列以及 原始正文的 或 getPeekedMessageItem() ,即不会尝试解码,以便可以检查正文,就像已从队列收到的那样。
处理程序不会尝试从队列中删除消息。 因此,此类处理应包含在处理程序本身中。
处理程序将由由此 QueueServiceClient 生成器创建或 QueueServiceAsyncClient 生成的所有队列客户端共享。
建议将此处理程序用于同步 QueueClient。
示例代码
String connectionString = "DefaultEndpointsProtocol=https;AccountName={name};"
+ "AccountKey={key};EndpointSuffix={core.windows.net}";
Consumer<QueueMessageDecodingError> processMessageDecodingErrorHandler =
(queueMessageDecodingFailure) -> {
QueueMessageItem queueMessageItem = queueMessageDecodingFailure.getQueueMessageItem();
PeekedMessageItem peekedMessageItem = queueMessageDecodingFailure.getPeekedMessageItem();
if (queueMessageItem != null) {
System.out.printf("Received badly encoded message, messageId=%s, messageBody=%s",
queueMessageItem.getMessageId(),
queueMessageItem.getBody().toString());
queueMessageDecodingFailure
.getQueueClient()
.deleteMessage(queueMessageItem.getMessageId(), queueMessageItem.getPopReceipt());
} else if (peekedMessageItem != null) {
System.out.printf("Peeked badly encoded message, messageId=%s, messageBody=%s",
peekedMessageItem.getMessageId(),
peekedMessageItem.getBody().toString());
}
};
QueueServiceClient client = new QueueServiceClientBuilder()
.connectionString(connectionString)
.processMessageDecodingError(processMessageDecodingErrorHandler)
.buildClient();
Parameters:
Returns:
processMessageDecodingErrorAsync
public QueueServiceClientBuilder processMessageDecodingErrorAsync(Function
设置异步处理程序,该处理程序执行从队列接收消息或达到峰值时所需的任务,但无法解码。
当队列预期是确定 QueueMessageEncoding 的,但有另一个生成者未按预期方式编码消息时,可能会收到此类消息或达到峰值。 即队列包含具有不同编码的消息。
QueueMessageDecodingError 包含 QueueAsyncClient 已接收消息 getQueueMessageItem() 的队列以及 原始正文的 或 getPeekedMessageItem() ,即不会尝试解码,以便可以检查正文,就像已从队列收到的那样。
处理程序不会尝试从队列中删除消息。 因此,此类处理应包含在处理程序本身中。
处理程序将由由此 QueueServiceClient 生成器创建或 QueueServiceAsyncClient 生成的所有队列客户端共享。
建议将此处理程序用于异步 QueueAsyncClient。
示例代码
String connectionString = "DefaultEndpointsProtocol=https;AccountName={name};"
+ "AccountKey={key};EndpointSuffix={core.windows.net}";
Function<QueueMessageDecodingError, Mono<Void>> processMessageDecodingErrorHandler =
(queueMessageDecodingFailure) -> {
QueueMessageItem queueMessageItem = queueMessageDecodingFailure.getQueueMessageItem();
PeekedMessageItem peekedMessageItem = queueMessageDecodingFailure.getPeekedMessageItem();
if (queueMessageItem != null) {
System.out.printf("Received badly encoded message, messageId=%s, messageBody=%s",
queueMessageItem.getMessageId(),
queueMessageItem.getBody().toString());
return queueMessageDecodingFailure
.getQueueAsyncClient()
.deleteMessage(queueMessageItem.getMessageId(), queueMessageItem.getPopReceipt());
} else if (peekedMessageItem != null) {
System.out.printf("Peeked badly encoded message, messageId=%s, messageBody=%s",
peekedMessageItem.getMessageId(),
peekedMessageItem.getBody().toString());
return Mono.empty();
} else {
return Mono.empty();
}
};
QueueServiceClient client = new QueueServiceClientBuilder()
.connectionString(connectionString)
.processMessageDecodingErrorAsync(processMessageDecodingErrorHandler)
.buildClient();
Parameters:
Returns:
retryOptions
public QueueServiceClientBuilder retryOptions(RetryOptions retryOptions)
RetryOptions为通过客户端发出的所有请求设置 。
注意: 请务必了解 HttpTrait API 的优先顺序。 具体而言,如果 HttpPipeline 指定了 ,则这优先于特征中的所有其他 API,它们将被忽略。 HttpPipeline如果未指定,则将基于提供给此特征的设置在内部构造 HTTP 管道。 此外,实现此特征的类型中可能存在其他 API,如果指定 了 , HttpPipeline 则也会忽略这些 API,因此请务必参考实现此特征的类型的文档以了解完整的含义集。
设置此项与使用 是互斥的 retryOptions(RequestRetryOptions retryOptions)。 请考虑使用 retryOptions(RequestRetryOptions retryOptions) 来同时设置特定于存储的选项。
Parameters:
Returns:
retryOptions
public QueueServiceClientBuilder retryOptions(RequestRetryOptions retryOptions)
为通过客户端发出的所有请求设置请求重试选项。 设置此项与使用 是互斥的 retryOptions(RetryOptions retryOptions)。
Parameters:
Returns:
sasToken
public QueueServiceClientBuilder sasToken(String sasToken)
设置用于授权发送到服务的请求的 SAS 令牌。
Parameters:
Returns:
serviceVersion
public QueueServiceClientBuilder serviceVersion(QueueServiceVersion version)
设置发出 QueueServiceVersion API 请求时使用的 。
如果未提供服务版本,将使用的服务版本将是基于正在使用的客户端库版本的最新已知服务版本。 如果未指定服务版本,更新到较新版本的客户端库可能会移动到较新的服务版本。
以特定服务版本为目标可能还意味着该服务将为较新的 API 返回错误。
Parameters:
Returns: