gpt4 book ai didi

c# - Cosmos DB 在实现自定义 BotState 服务后抛出 "Resource Not Found"错误

转载 作者:行者123 更新时间:2023-11-30 15:55:36 25 4
gpt4 key购买 nike

我们最近更新了我们的机器人,使用以下文章从即将弃用的默认 BotState 服务迁移到 Azure Cosmos DB 存储: https://learn.microsoft.com/en-us/bot-framework/dotnet/bot-builder-dotnet-state-azure-cosmosdb

以下模块在 Application_Start 方法中的 Conversation Container 中注册:

public class CustomBotStateServiceModule : Module
{
protected override void Load(ContainerBuilder builder)
{
var stateStore = new DocumentDbBotDataStore(
new Uri(ConfigurationManager.AppSettings.Get("EndpointUri")),
ConfigurationManager.AppSettings.Get("PrimaryKey"),
ConfigurationManager.AppSettings.Get("DatabaseId"),
"BotState");

builder.Register(c => stateStore)
.Keyed<IBotDataStore<BotData>>(AzureModule.Key_DataStore)
.AsSelf()
.SingleInstance();

builder.Register(c => new CachingBotDataStore(stateStore, CachingBotDataStoreConsistencyPolicy.ETagBasedConsistency))
.As<IBotDataStore<BotData>>()
.AsSelf()
.InstancePerLifetimeScope();
}
}

在我们使用 Bot Channel Emulator 进行本地测试期间,我们注意到,无论何时首次访问 BotState,Visual Studio 的调试输出中都会打印以下错误:

DocDBTrace Information: 0 : DocumentClient with id 1 initialized at endpoint: https://<our-instance>.documents.azure.com/ with ConnectionMode: Gateway, connection Protocol: Https, and consistency level: null
DocDBTrace Information: 0 : RefreshLocationAsync() refreshing locations
DocDBTrace Information: 0 : Set WriteEndpoint https://<our-instance>-westus.documents.azure.com/ ReadEndpoint https://<our-instance>-westus.documents.azure.com/
DocDBTrace Error: 0 : DocumentClientException with status code: NotFound, message: Message: {"Errors":["Resource Not Found"]}
ActivityId: <activity-id>, Request URI: /apps/<app-id>/services/<service-id>/partitions/<partition-id>/replicas/<replica-id>/, RequestStats:
ResponseTime: 2018-01-25T08:20:59.3067000Z, StoreReadResult: StorePhysicalAddress: rntbd://<docdb-location>.documents.azure.com:14043/apps/<app-id>/services/<service-id>/partitions/<partition-id>/replicas/<replica-id>/, LSN: 154, GlobalCommittedLsn: 151, PartitionKeyRangeId: 0, IsValid: True, StatusCode: 0, IsGone: False, IsNotFound: True, RequestCharge: 1, ItemLSN: -1, ResourceType: Document, OperationType: Read
, SDK: Microsoft.Azure.Documents.Common/1.19.162.2, and response headers: {
"x-ms-last-state-change-utc": "Wed, 24 Jan 2018 00:00:51.902 GMT",
"x-ms-schemaversion": "1.4",
"x-ms-xp-role": "1",
"x-ms-global-Committed-lsn": "151",
"x-ms-number-of-read-regions": "0",
"x-ms-request-charge": "1",
"x-ms-serviceversion": "version=1.19.162.2",
"x-ms-activity-id": "<activity-id>",
"Strict-Transport-Security": "max-age=31536000",
"x-ms-gatewayversion": "version=1.19.162.2",
"X-Cache": "MISS from <node>",
"Transfer-Encoding": "chunked",
"Connection": "keep-alive",
"Date": "Thu, 25 Jan 2018 08:20:58 GMT",
"Server": "Microsoft-HTTPAPI/2.0",
"Via": "1.1 <node> (squid)",
}
DocDBTrace Error: 0 : Operation will NOT be retried. Current attempt 0, Exception: Microsoft.Azure.Documents.DocumentClientException: Message: {"Errors":["Resource Not Found"]}
ActivityId: <activity-id>, Request URI: /apps/<app-id>/services/<service-id>/partitions/<partition-id>/replicas/<replica-id>/, RequestStats:
ResponseTime: 2018-01-25T08:20:59.3067000Z, StoreReadResult: StorePhysicalAddress: rntbd://<docdb-location>.documents.azure.com:14043/apps/<app-id>/services/<service-id>/partitions/<partition-id>/replicas/<replica-id>/, LSN: 154, GlobalCommittedLsn: 151, PartitionKeyRangeId: 0, IsValid: True, StatusCode: 0, IsGone: False, IsNotFound: True, RequestCharge: 1, ItemLSN: -1, ResourceType: Document, OperationType: Read
, SDK: Microsoft.Azure.Documents.Common/1.19.162.2, documentdb-dotnet-sdk/1.19.1 Host/32-bit MicrosoftWindowsNT6.1.7601ServicePack1
at Microsoft.Azure.Documents.Client.ClientExtensions.<ParseResponseAsync>d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
at Microsoft.Azure.Documents.GatewayStoreModel.<>c__DisplayClass10.<<InvokeAsync>b__f>d__12.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Azure.Documents.BackoffRetryUtility`1.<>c__DisplayClass2.<<ExecuteAsync>b__0>d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Azure.Documents.BackoffRetryUtility`1.<ExecuteRetry>d__1b.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at Microsoft.Azure.Documents.BackoffRetryUtility`1.<ExecuteRetry>d__1b.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Azure.Documents.BackoffRetryUtility`1.<ExecuteAsync>d__a.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Azure.Documents.GatewayStoreModel.<InvokeAsync>d__1f.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Azure.Documents.GatewayStoreModel.<ProcessMessageAsync>d__2.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Azure.Documents.Client.DocumentClient.<ReadAsync>d__30c.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Azure.Documents.Client.DocumentClient.<ReadDocumentPrivateAsync>d__18d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Azure.Documents.BackoffRetryUtility`1.<>c__DisplayClass2.<<ExecuteAsync>b__0>d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Azure.Documents.BackoffRetryUtility`1.<ExecuteRetry>d__1b.MoveNext()

这些错误不久之后又打印了大约 1-2 次。尽管如此,我们的自定义 BotState 服务似乎工作正常,因为我们可以看到在相关 Cosmos DB 集合中创建的条目。

注意:我们并没有专门使用我们的 Cosmos DB 来存储 BotState 数据。我们还用它来存储机器人事件数据、日志等。它目前有两个具有多个集合的数据库。

这些错误的根本原因是什么?这是我们应该考虑警告的事情吗?一旦我们从容器注册中拔出自定义 BotState 服务,错误就消失了。

最佳答案

我可以在我这边重现这个问题,根据我的测试和研究,我发现当我们想将状态数据存储到 Azure Cosmos DB 集合时,Azure SDK 帮助我们检查文档是否存在,所以你可以看到该输出消息:当您的机器人应用程序首次存储数据时,您的 Visual Studio 输出窗口中的 "Resource Not Found"

enter image description here

如果您使用 Fiddler 捕获流量,您会发现 SDK 发出请求以检测该文档是否存在于该集合中。

enter image description here

如您所见,它只是SDK编写的输出消息,不会导致您的代码出现任何代码异常。

关于c# - Cosmos DB 在实现自定义 BotState 服务后抛出 "Resource Not Found"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48441262/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com