CosmosDBTrigger Interface
Implements
public interface CosmosDBTrigger implements java.lang.annotation.Annotation
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
- Any POJO type
The following example shows a Java function that is invoked when there are inserts or updates in the specified database and collection.
@FunctionName("cosmosDBMonitor")
public void cosmosDbLog(
@CosmosDBTrigger(name = "database",
databaseName = "ToDoList",
collectionName = "Items",
leaseCollectionName = "leases",
createLeaseCollectionIfNotExists = true,
connectionStringSetting = "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"));
}
}
Method Summary
Modifier and Type | Method and Description |
---|---|
abstract int |
checkpointDocumentCount()
Customizes the amount of documents between lease checkpoints. |
abstract int |
checkpointInterval()
Customizes the amount of milliseconds between lease checkpoints. |
abstract java.lang.String |
collectionName()
Defines the collection name of the CosmosDB to which to bind. |
abstract java.lang.String |
connectionStringSetting()
Defines the app setting name that contains the CosmosDB connection string. |
abstract boolean |
createLeaseCollectionIfNotExists()
Defines whether to create a new lease collection if not exists. |
abstract java.lang.String |
dataType()
Defines how Functions runtime should treat the parameter value. |
abstract java.lang.String |
databaseName()
Defines the database name of the CosmosDB to which to bind. |
abstract int |
feedPollDelay()
Customizes the delay in milliseconds in between polling a partition for new changes on the feed, after all current changes are drained. |
abstract int |
leaseAcquireInterval()
Customizes the interval in milliseconds to kick off a task to compute if partitions are distributed evenly among known host instances. |
abstract java.lang.String |
leaseCollectionName()
Defines the lease collection name of the CosmosDB to which to bind. |
abstract java.lang.String |
leaseCollectionPrefix()
Defines a prefix to be used within a Leases collection for this Trigger. |
abstract java.lang.String |
leaseConnectionStringSetting()
Defines Connection string for the service containing the lease collection. |
abstract java.lang.String |
leaseDatabaseName()
Defines Name of the database containing the lease collection. |
abstract int |
leaseExpirationInterval()
Customizes the interval in milliseconds for which the lease is taken on a lease representing a partition. |
abstract int |
leaseRenewInterval()
Customizes the renew interval in milliseconds for all leases for partitions currently held by the Trigger. |
abstract int |
leasesCollectionThroughput()
defines the throughput of the created collection.. |
abstract int |
maxItemsPerInvocation()
Customizes the maximum amount of items received in an invocation |
abstract java.lang.String |
name()
The variable name used in function. |
abstract java.lang.String |
preferredLocations()
Defines preferred locations (regions) for geo-replicated database accounts in the Azure Cosmos DB service. |
abstract boolean |
startFromBeginning()
Gets or sets whether change feed in the Azure Cosmos DB service should start from beginning (true) or from current (false). |
Method Details
checkpointDocumentCount
public abstract int checkpointDocumentCount()
Customizes the amount of documents between lease checkpoints. Default is always after a Function call.
Returns:
checkpointInterval
public abstract int checkpointInterval()
Customizes the amount of milliseconds between lease checkpoints. Default is always after a Function call.
Returns:
collectionName
public abstract String collectionName()
Defines the collection name of the CosmosDB to which to bind.
Returns:
connectionStringSetting
public abstract String connectionStringSetting()
Defines the app setting name that contains the CosmosDB connection string.
Returns:
createLeaseCollectionIfNotExists
public abstract boolean createLeaseCollectionIfNotExists()
Defines whether to create a new lease collection if not exists.
Returns:
dataType
public abstract 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:
databaseName
public abstract String databaseName()
Defines the database name of the CosmosDB to which to bind.
Returns:
feedPollDelay
public abstract 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:
leaseAcquireInterval
public abstract 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:
leaseCollectionName
public abstract String leaseCollectionName()
Defines the lease collection name of the CosmosDB to which to bind.
Returns:
leaseCollectionPrefix
public abstract String leaseCollectionPrefix()
Defines a prefix to be used within a Leases collection for this Trigger. Useful when sharing the same Lease collection among multiple Triggers.
Returns:
leaseConnectionStringSetting
public abstract String leaseConnectionStringSetting()
Defines Connection string for the service containing the lease collection.
Returns:
leaseDatabaseName
public abstract String leaseDatabaseName()
Defines Name of the database containing the lease collection.
Returns:
leaseExpirationInterval
public abstract 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:
leaseRenewInterval
public abstract int leaseRenewInterval()
Customizes the renew interval in milliseconds for all leases for partitions currently held by the Trigger. Default is 17000 (17 seconds).
Returns:
leasesCollectionThroughput
public abstract int leasesCollectionThroughput()
defines the throughput of the created collection..
Returns:
maxItemsPerInvocation
public abstract int maxItemsPerInvocation()
Customizes the maximum amount of items received in an invocation
Returns:
name
public abstract String name()
The variable name used in function.json.
Returns:
preferredLocations
public abstract 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:
startFromBeginning
public abstract 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:
Applies to
Azure SDK for Java