javaazure-functionsazure-cosmosdbazure-cosmosdb-mongoapicosmosdbtrigger

azure function java CosmosDBTrigger-input and @SignalROutput-output, Error :Cannot create Collection Information


I have replaced secured data with placeholders

Error while running locally as well as after deploying -

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 file -

{
  "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
  }
}

Code -

@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);

Collection and DB are already created but I haven't created lease collection.

I am working on realtime application using cosmos db, signalr and azure function but i am stuck with this error for quite some time now.


Solution

  • You seem to be using a Mongo account (your endpoint is <Azure-Cosmos-DB-Account>.mongo.cosmos.azure.com).

    As per the documentation:

    Azure Cosmos DB bindings are only supported for use with the SQL API.