Azure / azure-functions-java-library

Contains annotations for writing Azure Functions in Java
MIT License
43 stars 43 forks source link

CosmosDB Outputbinding does not work for multiple documents #109

Open cepxy opened 4 years ago

cepxy commented 4 years ago

We have a simple function which is triggered by event hub and simply forwards messages to cosmosDB using the cosmosDB output binding. It works well if we receive and forward one message. However it does not work when we receive and forward a list of messages using Cardinality.many. Example:

public void run(
    @EventHubTrigger(
            name = "ConsumeDeviceMessages2",
            eventHubName = "@eventhub.name@",
            connection = "@iothub.connection@",
            consumerGroup = CONSUMER_GROUP,
            cardinality = Cardinality.MANY)
            List<String> messages,

    @CosmosDBOutput(
            name = "outputDocument",
            databaseName = "@cosmosdb.name@",
            collectionName = "@cosmosdb.collection.name@",
            connectionStringSetting = "@cosmosdb.connection.appsetting@")
            OutputBinding<List<String>> outputDocument,

    final ExecutionContext context) {
    outputDocument.setValue(messages);
}

If this is triggered an error occurs:

[Error] Executed 'Functions.SaveIotDeviceMessages' (Failed, Id=a845d74b-861a-40e7-a6f2-f5b7032b2cf2)Value cannot be null.Parameter name: document

Configuration seems pretty basic and works on another function where we forward multiple messages to a queue instead.

Any idea why it is not working for cosmosDB? The documentation states its working for .NET and Javascript, no information about Java though.

Thanks and regards.