你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn。
CosmosClientBuilder 构造函数
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
重载
CosmosClientBuilder(String) |
从连接字符串中提取帐户终结点和密钥。 |
CosmosClientBuilder(String, AzureKeyCredential) |
使用帐户终结点 URI 字符串和 AzureKeyCredential 初始化一个新的 CosmosConfiguration 类,该类包含 CosmosClient 所需的所有属性。 AzureKeyCredential 允许在 CosmosClient 仍在使用时更改/更新 master-key/ResourceToken。 |
CosmosClientBuilder(String, TokenCredential) |
使用 TokenCredential 实例初始化新的 CosmosClientBuilder 。 |
CosmosClientBuilder(String, String) |
初始化一个新的 CosmosConfiguration 类,该类包含 CosmosClient 所需的所有属性。 |
CosmosClientBuilder(String)
从连接字符串中提取帐户终结点和密钥。
public CosmosClientBuilder (string connectionString);
new Microsoft.Azure.Cosmos.Fluent.CosmosClientBuilder : string -> Microsoft.Azure.Cosmos.Fluent.CosmosClientBuilder
Public Sub New (connectionString As String)
参数
- connectionString
- String
连接字符串必须包含 AccountEndpoint 和 AccountKey 或 ResourceToken。
示例
“AccountEndpoint=https://mytestcosmosaccount.documents.azure.com:443/;AccountKey={SecretAccountKey};”
适用于
CosmosClientBuilder(String, AzureKeyCredential)
使用帐户终结点 URI 字符串和 AzureKeyCredential 初始化一个新的 CosmosConfiguration 类,该类包含 CosmosClient 所需的所有属性。 AzureKeyCredential 允许在 CosmosClient 仍在使用时更改/更新 master-key/ResourceToken。
public CosmosClientBuilder (string accountEndpoint, Azure.AzureKeyCredential authKeyOrResourceTokenCredential);
new Microsoft.Azure.Cosmos.Fluent.CosmosClientBuilder : string * Azure.AzureKeyCredential -> Microsoft.Azure.Cosmos.Fluent.CosmosClientBuilder
Public Sub New (accountEndpoint As String, authKeyOrResourceTokenCredential As AzureKeyCredential)
参数
- accountEndpoint
- String
Cosmos 帐户的 URI。 示例:https://{Cosmos 帐户名称}.documents.azure.com:443/
- authKeyOrResourceTokenCredential
- AzureKeyCredential
具有主密钥或资源令牌的 AzureKeyCredential。
示例
下面的示例创建新的 CosmosClientBuilder
CosmosClientBuilder cosmosClientBuilder = new CosmosClientBuilder(
accountEndpoint: "https://testcosmos.documents.azure.com:443/",
authKeyOrResourceTokenCredential: new AzureKeyCredential("SuperSecretKey"));
CosmosClient client = cosmosClientBuilder.Build();
以下示例使用 ConsistencyLevel 和首选位置列表创建新的 CosmosClientBuilder 。
CosmosClientBuilder cosmosClientBuilder = new CosmosClientBuilder(
accountEndpoint: "https://testcosmos.documents.azure.com:443/",
authKeyOrResourceTokenCredential: new AzureKeyCredential("SuperSecretKey"))
.WithConsistencyLevel(ConsistencyLevel.Strong)
.WithApplicationRegion("East US 2");
CosmosClient client = cosmosClientBuilder.Build();
注解
AzureKeyCredential 允许更改/更新 master-key/ResourceToken whle CosmosClient 仍在使用中。
适用于
CosmosClientBuilder(String, TokenCredential)
使用 TokenCredential 实例初始化新的 CosmosClientBuilder 。
public CosmosClientBuilder (string accountEndpoint, Azure.Core.TokenCredential tokenCredential);
new Microsoft.Azure.Cosmos.Fluent.CosmosClientBuilder : string * Azure.Core.TokenCredential -> Microsoft.Azure.Cosmos.Fluent.CosmosClientBuilder
Public Sub New (accountEndpoint As String, tokenCredential As TokenCredential)
参数
- accountEndpoint
- String
Cosmos 帐户的 URI。 示例:https://{Cosmos 帐户名称}.documents.azure.com:443/
- tokenCredential
- TokenCredential
的一个实例。TokenCredential
示例
下面的示例使用 TokenCredential创建新的 CosmosClientBuilder 。
CosmosClientBuilder cosmosClientBuilder = new CosmosClientBuilder(
accountEndpoint: "https://testcosmos.documents.azure.com:443/",
tokenCredential: new DefaultAzureCredential());
CosmosClient client = cosmosClientBuilder.Build();
适用于
CosmosClientBuilder(String, String)
初始化一个新的 CosmosConfiguration 类,该类包含 CosmosClient 所需的所有属性。
public CosmosClientBuilder (string accountEndpoint, string authKeyOrResourceToken);
new Microsoft.Azure.Cosmos.Fluent.CosmosClientBuilder : string * string -> Microsoft.Azure.Cosmos.Fluent.CosmosClientBuilder
Public Sub New (accountEndpoint As String, authKeyOrResourceToken As String)
参数
- accountEndpoint
- String
Cosmos 帐户的 URI。 示例:https://{Cosmos 帐户名称}.documents.azure.com:443/
- authKeyOrResourceToken
- String
帐户或资源令牌的密钥。
示例
下面的示例创建新的 CosmosClientBuilder
CosmosClientBuilder cosmosClientBuilder = new CosmosClientBuilder(
accountEndpoint: "https://testcosmos.documents.azure.com:443/",
authKeyOrResourceToken: "SuperSecretKey");
CosmosClient client = cosmosClientBuilder.Build();
以下示例使用 ConsistencyLevel 和首选位置列表创建新的 CosmosClientBuilder 。
CosmosClientBuilder cosmosClientBuilder = new CosmosClientBuilder(
accountEndpoint: "https://testcosmos.documents.azure.com:443/",
authKeyOrResourceToken: "SuperSecretKey")
.WithConsistencyLevel(ConsistencyLevel.Strong)
.WithApplicationRegion("East US 2");
CosmosClient client = cosmosClientBuilder.Build();