Skip to content

Commit

Permalink
Updating to latest extension
Browse files Browse the repository at this point in the history
  • Loading branch information
ealsur committed Apr 7, 2023
1 parent f6d58fc commit 39a6d53
Showing 1 changed file with 21 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ author: ealsur
ms.service: cosmos-db
ms.subservice: nosql
ms.topic: how-to
ms.date: 07/17/2019
ms.date: 4/07/2023
ms.author: maquaran
ms.devlang: csharp
ms.custom: devx-track-csharp
Expand Down Expand Up @@ -37,16 +37,15 @@ The goal of this article is to guide you to accomplish the second option.

## Configuring a shared leases container

To configure the shared leases container, the only extra configuration you need to make on your triggers is to add the `LeaseCollectionPrefix` [attribute](../../azure-functions/functions-bindings-cosmosdb-v2-trigger.md#attributes) if you are using C# or `leaseCollectionPrefix` [attribute](../../azure-functions/functions-bindings-cosmosdb-v2-trigger.md) if you are using JavaScript. The value of the attribute should be a logical descriptor of what that particular trigger.
To configure the shared leases container, the only extra configuration you need to make on your triggers is to add the `LeaseContainerPrefix` [attribute](../../azure-functions/functions-bindings-cosmosdb-v2-trigger.md#attributes) if you are using C# or `leaseContainerPrefix` [attribute](../../azure-functions/functions-bindings-cosmosdb-v2-trigger.md) if you are using JavaScript. The value of the attribute should be a logical descriptor of what that particular trigger.

For example, if you have three Triggers: one that sends emails, one that does an aggregation to create a materialized view, and one that sends the changes to another storage, for later analysis, you could assign the `LeaseCollectionPrefix` of "emails" to the first one, "materialized" to the second one, and "analytics" to the third one.
For example, if you have three Triggers: one that sends emails, one that does an aggregation to create a materialized view, and one that sends the changes to another storage, for later analysis, you could assign the `LeaseContainerPrefix` of "emails" to the first one, "materialized" to the second one, and "analytics" to the third one.

The important part is that all three Triggers **can use the same leases container configuration** (account, database, and container name).

A very simple code samples using the `LeaseCollectionPrefix` attribute in C#, would look like this:
A very simple code samples using the `LeaseContainerPrefix` attribute in C#, would look like this:

```cs
using Microsoft.Azure.Documents;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Host;
using System.Collections.Generic;
Expand All @@ -55,10 +54,10 @@ using Microsoft.Extensions.Logging;
[FunctionName("SendEmails")]
public static void SendEmails([CosmosDBTrigger(
databaseName: "ToDoItems",
collectionName: "Items",
ConnectionStringSetting = "CosmosDBConnection",
LeaseCollectionName = "leases",
LeaseCollectionPrefix = "emails")]IReadOnlyList<Document> documents,
containerName: "Items",
Connection = "CosmosDBConnection",
LeaseContainerName = "leases",
LeaseContainerPrefix = "emails")]IReadOnlyList<MyItem> items,
ILogger log)
{
...
Expand All @@ -67,38 +66,38 @@ public static void SendEmails([CosmosDBTrigger(
[FunctionName("MaterializedViews")]
public static void MaterializedViews([CosmosDBTrigger(
databaseName: "ToDoItems",
collectionName: "Items",
ConnectionStringSetting = "CosmosDBConnection",
LeaseCollectionName = "leases",
LeaseCollectionPrefix = "materialized")]IReadOnlyList<Document> documents,
containerName: "Items",
Connection = "CosmosDBConnection",
LeaseContainerName = "leases",
LeaseContainerPrefix = "materialized")]IReadOnlyList<MyItem> items,
ILogger log)
{
...
}
```

And for JavaScript, you can apply the configuration on the `function.json` file, with the `leaseCollectionPrefix` attribute:
And for JavaScript, you can apply the configuration on the `function.json` file, with the `leaseContainerPrefix` attribute:

```json
{
"type": "cosmosDBTrigger",
"name": "documents",
"direction": "in",
"leaseCollectionName": "leases",
"connectionStringSetting": "CosmosDBConnection",
"leaseContainerName": "leases",
"connection": "CosmosDBConnection",
"databaseName": "ToDoItems",
"collectionName": "Items",
"leaseCollectionPrefix": "emails"
"containerName": "Items",
"leaseContainerPrefix": "emails"
},
{
"type": "cosmosDBTrigger",
"name": "documents",
"direction": "in",
"leaseCollectionName": "leases",
"connectionStringSetting": "CosmosDBConnection",
"leaseContainerName": "leases",
"connection": "CosmosDBConnection",
"databaseName": "ToDoItems",
"collectionName": "Items",
"leaseCollectionPrefix": "materialized"
"containerName": "Items",
"leaseContainerPrefix": "materialized"
}
```

Expand Down

0 comments on commit 39a6d53

Please sign in to comment.