Rak*_*mar 3 azure-cosmosdb azure-cosmosdb-sqlapi
我正在尝试使用本地设置将新项目添加到 cosmos 数据库中。
这是我的批量插入代码:
private async Task AddSubscription(EnableOrDisableSubscriptionCommand command, SubscriptionAction subscriptionAction, IList<int> notificationCategoryTypes)
{
List<Task> bulkOperations = new List<Task>();
foreach (var notificationCategory in notificationCategoryTypes)
{
var notificationTypes = Utility.GetNotificationTypes((NotificationCategoryType)notificationCategory);
foreach (var notificationType in notificationTypes)
{
foreach (var payerAccountSubscriptions in command.Subscriptions)
{
if (payerAccountSubscriptions.AccountNumbers?.Any() ?? false)
{
foreach (var accountNumber in payerAccountSubscriptions.AccountNumbers.Where(a => !string.IsNullOrEmpty(a)))
{
bulkOperations.Add(_repository.Create(subscriptionAction, notificationType,
payerAccountSubscriptions.ColCoId, payerAccountSubscriptions.PayerNumber, accountNumber, command.UserRole,
command.UserId));
}
}
else
{
bulkOperations.Add(_repository.Create(subscriptionAction, notificationType,
payerAccountSubscriptions.ColCoId, payerAccountSubscriptions.PayerNumber, null, command.UserRole,
command.UserId));
}
}
}
}
await Task.WhenAll(bulkOperations);
}
public Task<ItemResponse<T>> CreateItemAsync(T item, string partitionKeyValue)
{
return _container.CreateItemAsync<T>(item, new PartitionKey(partitionKeyValue));
}
Run Code Online (Sandbox Code Playgroud)
本地.settings.json:
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"AzureWebJobsDashboard": "UseDevelopmentStorage=true",
"FUNCTIONS_WORKER_RUNTIME": "dotnet",
//localhost
"CosmosDbId": "Notifications",
"CosmoDbAuthKey": "C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==",
"CosmoDbEndpoint": "https://localhost:8081/",
}
}
Run Code Online (Sandbox Code Playgroud)
我已经安装了 Azure Cosmos DB 模拟器。
我收到以下错误,该错误未提供太多信息?
[8/31/2020 6:49:10 AM] System.Private.CoreLib:执行函数时出现异常:EnableOrDisableSubscriptions。Microsoft.Azure.Cosmos.Client:响应状态代码不表示成功:ServiceUnavailable (503);子状态:0;活动
我在 Cosmos DB SQL API 入门指南之后遇到了同样的问题。
修复方法是指定ConnectionMode = ConnectionMode.Gateway
var cosmosClient = new CosmosClient(EndpointUrl, AuthorizationKey, new CosmosClientOptions() { AllowBulkExecution = true, ConnectionMode = ConnectionMode.Gateway });
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8240 次 |
| 最近记录: |