Annotation Type CosmosDBTrigger


  • @Retention(RUNTIME)
    @Target(PARAMETER)
    public @interface CosmosDBTrigger

    Place this on a parameter whose value would come from CosmosDB, and causing the method to run when CosmosDB data is changed. The parameter type can be one of the following:

    • Some native Java types such as String
    • Nullable values using Optional<T>
    • Any POJO type

    The following example shows a Java function that is invoked when there are inserts or updates in the specified database and container.

     @FunctionName("cosmosDBMonitor")
     public void cosmosDbLog(
        @CosmosDBTrigger(name = "database",
                          databaseName = "ToDoList",
                          containerName = "Items",
                          leaseContainerName = "leases",
                          createLeaseContainerIfNotExists = true,
                          connection = "AzureCosmosDBConnection")
                          List<Map<String, String>> items,
         final ExecutionContext context
     ) {
         context.getLogger().info(items.size() + " item(s) is/are inserted.");
         if (!items.isEmpty()) {
             context.getLogger().info("The ID of the first item is: " + items.get(0).get("id"));
         }
     }
     
    Since:
    1.0.0
    • Required Element Summary

      Required Elements 
      Modifier and Type Required Element Description
      java.lang.String connection
      Defines the app setting name that contains the CosmosDB connection string.
      java.lang.String containerName
      Defines the container name of the CosmosDB to which to bind.
      java.lang.String databaseName
      Defines the database name of the CosmosDB to which to bind.
      java.lang.String name
      The variable name used in function.json.
    • Optional Element Summary

      Optional Elements 
      Modifier and Type Optional Element Description
      int checkpointDocumentCount
      Customizes the amount of documents between lease checkpoints.
      int checkpointInterval
      Customizes the amount of milliseconds between lease checkpoints.
      boolean createLeaseContainerIfNotExists
      Defines whether to create a new lease container if not exists.
      java.lang.String dataType
      Defines how Functions runtime should treat the parameter value.
      int feedPollDelay
      Customizes the delay in milliseconds in between polling a partition for new changes on the feed, after all current changes are drained.
      int leaseAcquireInterval
      Customizes the interval in milliseconds to kick off a task to compute if partitions are distributed evenly among known host instances.
      java.lang.String leaseConnectionStringSetting
      Defines Connection string for the service containing the lease container.
      java.lang.String leaseContainerName
      Defines the lease container name of the CosmosDB to which to bind.
      java.lang.String leaseContainerPrefix
      Defines a prefix to be used within a Leases container for this Trigger.
      java.lang.String leaseDatabaseName
      Defines Name of the database containing the lease container.
      int leaseExpirationInterval
      Customizes the interval in milliseconds for which the lease is taken on a lease representing a partition.
      int leaseRenewInterval
      Customizes the renew interval in milliseconds for all leases for partitions currently held by the Trigger.
      int leasesContainerThroughput
      defines the throughput of the created container.
      int maxItemsPerInvocation
      Customizes the maximum amount of items received in an invocation
      java.lang.String preferredLocations
      Defines preferred locations (regions) for geo-replicated database accounts in the Azure Cosmos DB service.
      boolean startFromBeginning
      Gets or sets whether change feed in the Azure Cosmos DB service should start from beginning (true) or from current (false).
    • Element Detail

      • name

        java.lang.String name
        The variable name used in function.json.
        Returns:
        The variable name used in function.json.
      • databaseName

        java.lang.String databaseName
        Defines the database name of the CosmosDB to which to bind.
        Returns:
        The database name string.
      • containerName

        java.lang.String containerName
        Defines the container name of the CosmosDB to which to bind.
        Returns:
        The container name string.
      • connection

        java.lang.String connection
        Defines the app setting name that contains the CosmosDB connection string.
        Returns:
        The app setting name of the connection string.
      • dataType

        java.lang.String dataType

        Defines how Functions runtime should treat the parameter value. Possible values are:

        • "": get the value as a string, and try to deserialize to actual parameter type like POJO
        • string: always get the value as a string
        • binary: get the value as a binary data, and try to deserialize to actual parameter type byte[]
        Returns:
        The dataType which will be used by the Functions runtime.
        Default:
        ""
      • leaseConnectionStringSetting

        java.lang.String leaseConnectionStringSetting
        Defines Connection string for the service containing the lease container.
        Returns:
        Connection string for the lease container.
        Default:
        ""
      • leaseContainerName

        java.lang.String leaseContainerName
        Defines the lease container name of the CosmosDB to which to bind.
        Returns:
        The lease container name string.
        Default:
        ""
      • leaseDatabaseName

        java.lang.String leaseDatabaseName
        Defines Name of the database containing the lease container.
        Returns:
        Name of the database for lease container.
        Default:
        ""
      • createLeaseContainerIfNotExists

        boolean createLeaseContainerIfNotExists
        Defines whether to create a new lease container if not exists.
        Returns:
        configuration whether to create a new lease container if not exists.
        Default:
        false
      • leasesContainerThroughput

        int leasesContainerThroughput
        defines the throughput of the created container.
        Returns:
        throughput
        Default:
        -1
      • leaseContainerPrefix

        java.lang.String leaseContainerPrefix
        Defines a prefix to be used within a Leases container for this Trigger. Useful when sharing the same Lease container among multiple Triggers.
        Returns:
        LeaseContainerPrefix
        Default:
        ""
      • checkpointInterval

        int checkpointInterval
        Customizes the amount of milliseconds between lease checkpoints. Default is always after a Function call.
        Returns:
        checkpointInterval
        Default:
        -1
      • checkpointDocumentCount

        int checkpointDocumentCount
        Customizes the amount of documents between lease checkpoints. Default is always after a Function call.
        Returns:
        CheckpointDocumentCount
        Default:
        -1
      • feedPollDelay

        int feedPollDelay
        Customizes the delay in milliseconds in between polling a partition for new changes on the feed, after all current changes are drained. Default is 5000 (5 seconds).
        Returns:
        feedPollDelay
        Default:
        5000
      • leaseRenewInterval

        int leaseRenewInterval
        Customizes the renew interval in milliseconds for all leases for partitions currently held by the Trigger. Default is 17000 (17 seconds).
        Returns:
        renew interval in milliseconds for all leases
        Default:
        17000
      • leaseAcquireInterval

        int leaseAcquireInterval
        Customizes the interval in milliseconds to kick off a task to compute if partitions are distributed evenly among known host instances. Default is 13000 (13 seconds).
        Returns:
        interval in milliseconds
        Default:
        13000
      • leaseExpirationInterval

        int leaseExpirationInterval
        Customizes the interval in milliseconds for which the lease is taken on a lease representing a partition. If the lease is not renewed within this interval, it will cause it to expire and ownership of the partition will move to another Trigger instance. Default is 60000 (60 seconds).
        Returns:
        interval in milliseconds for which the lease is taken
        Default:
        60000
      • maxItemsPerInvocation

        int maxItemsPerInvocation
        Customizes the maximum amount of items received in an invocation
        Returns:
        maximum amount of items received
        Default:
        -1
      • startFromBeginning

        boolean startFromBeginning
        Gets or sets whether change feed in the Azure Cosmos DB service should start from beginning (true) or from current (false). By default it's start from current (false).
        Returns:
        Configuration whether change feed should start from beginning
        Default:
        false
      • preferredLocations

        java.lang.String preferredLocations
        Defines preferred locations (regions) for geo-replicated database accounts in the Azure Cosmos DB service. Values should be comma-separated. example, PreferredLocations = "East US,South Central US,North Europe"
        Returns:
        preferred locations (regions) for geo-replicated database accounts
        Default:
        ""