首页 > 解决方案 > 使用 Cosmos DB 的 Hangfire:响应状态代码不表示成功:NotFound (404);子状态:0;活动 ID

问题描述

我有使用 Cosmos DB 作为数据库的 Hangfire。当我选择重试选项卡时,我收到错误:

An unhandled exception occurred while processing the request.
AggregateException: One or more errors occurred. (Response status code does not indicate success: NotFound (404); Substatus: 0; ActivityId: 68d632fc-8c5a-4624-80a5-7e9bc0d252f0; Reason: ({
"Errors": [
"Resource Not Found. Learn more: https://aka.ms/cosmosdb-tsg-not-found"
]
});)
System.Threading.Tasks.Task.Wait(int millisecondsTimeout, CancellationToken cancellationToken)

CosmosException: Response status code does not indicate success: NotFound (404); Substatus: 0; ActivityId: 68d632fc-8c5a-4624-80a5-7e9bc0d252f0; Reason: ({
"Errors": [
"Resource Not Found. Learn more: https://aka.ms/cosmosdb-tsg-not-found"
]
});
Microsoft.Azure.Cosmos.ResponseMessage.EnsureSuccessStatusCode()

当我尝试在 Cosmos DB 上进行 select 语句以获取具有以下内容的项目时key='retries'

SELECT * FROM c where c.key = 'retries' and c.value = 'b7ad3971-8647-4a29-a2a7-412e2da41527'

我在 Cosmos DB 中遇到错误:

Failed to query item for container hangfire:
 Gateway Failed to Retrieve Query Plan: Message: {"errors":[{"severity":"Error","location":{"start":46,"end":51},"code":"SC1001","message":"Syntax error, incorrect syntax near 'value'."}]}

ActivityId: 4bc1d85a-4ea6-47c2-95d0-81bdde78f389, Microsoft.Azure.Documents.Common/2.11.0, Microsoft.Azure.Documents.Common/2.11.0

当我这样选择时:

SELECT * FROM c where c.key = 'retries'

我可以看到没有错误的结果。添加AND c.value=...到 where 子句时发生错误。我无法在 上打开重试选项卡Hangfire dashboard。Cosmos 中的 Json 看起来像:

{
        "key": "retries",
        "value": "b7ad3971-8647-4a29-a2a7-412e2da41527",
        "score": 0,
        "created_on": 1611580578,
        "type": 7,
        "id": "b04c5c23-d324-45e1-acce-cdd2379c4073",
        "_rid": "QO5WANzKkljY-gEAAAAAAA==",
        "_self": "dbs/QO5WAA==/colls/QO5WANzKklg=/docs/QO5WANzKkljY-gEAAAAAAA==/",
        "_etag": "\"2d01ed73-0000-0100-0000-600ec4a30000\"",
        "_attachments": "attachments/",
        "_ts": 1611580579
    },

标签: azure-cosmosdbhangfire

解决方案


您收到此错误的原因是因为value是关键字。请尝试以下查询,它应该可以工作:

SELECT * FROM c where c.key = 'retries' and c["value"] = 'b7ad3971-8647-4a29-a2a7-412e2da41527'

推荐阅读