azure 函数java CosmosDBTrigger-input和@ SignalROutput-output,错误:无法创建集合信息

2020年11月14日 46点热度 0条评论

我已用占位符替换了安全数据

在本地运行以及部署后出现错误-

Microsoft.Azure.WebJobs.Host: Error indexing method 'Functions.<Function-Name>'. Microsoft.Azure.WebJobs.Extensions.CosmosDB: Cannot create Collection Information for <Collection-Name> in database <Database-Name> with lease <Lease-Collection-Name> in database <Database-Name> : 
RequestUri: https://<Azure-Cosmos-DB-Account>.mongo.cosmos.azure.com/;
RequestMethod: GET;
Header: x-ms-version Length: 10;
Header: User-Agent Length: 48;
Header: x-ms-date Length: 29;
Header: Authorization Length: 82;
, Request URI: /, RequestStats: , SDK: Windows/10.0.18362 documentdb-netcore-sdk/2.10.1. Microsoft.Azure.DocumentDB.Core: 

local.settings.json文件-

{
  "IsEncrypted": false,
  "Values": {
    "JAVA_OPTS": "-Djava.net.preferIPv4Stack=true -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=127.0.0.1:5005",
    "AzureWebJobsStorage": "<Required value>",
    "AzureWebJobsDashboard": "<Required value>",
    "AzureSignalRConnectionString": "<Endpoint connection string>",
    "AzureCosmosDBConnection": "AccountEndpoint=https://<Azure Cosmos Db Account>.mongo.cosmos.azure.com:443/;AccountKey=<Required key>",
    "FUNCTIONS_WORKER_RUNTIME": "java"
  },
  "Host": {
    "LocalHttpPort": 7071,
    "CORS": "http://localhost:8080,http://localhost:4200",
    "CORSCredentials": true
  }
}

代码-

@FunctionName("Notify-Update")
    public void notifyDBUpdate(
            @CosmosDBTrigger(name = "dataInput",
                    databaseName = "demo",
                    collectionName = "bagi",
                    leaseDatabaseName = "demo",
                    leaseCollectionName = "leasebagi",
                    createLeaseCollectionIfNotExists = true,
                    connectionStringSetting = "AzureCosmosDBConnection")
                    String document,
            @SignalROutput(name = "dataOutput", hubName = "chat", connectionStringSetting = "AzureSignalRConnectionString") OutputBinding<String> dataOutput,
            final ExecutionContext context) {

        context.getLogger().info("Java CosmosDB Notification trigger processed a request: " + document);

集合和数据库已经创建,但是我还没有创建租赁集合。

我正在使用cosmos db,signaler和azure函数进行实时应用程序开发,但是我在相当长的一段时间内一直停留在此错误上。

解决方案如下:

您似乎正在使用Mongo帐户(您的端点是<Azure-Cosmos-DB-Account>.mongo.cosmos.azure.com)。

根据documentation

仅支持将Azure Cosmos DB绑定与SQL API一起使用。