You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/cosmos-db/create-sql-api-java-changefeed.md
+13-13Lines changed: 13 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
---
2
2
title: Create an end-to-end Azure Cosmos DB Java SDK v4 application sample by using Change Feed
3
-
description: This how-to guide walks you through a simple Java SQL API application which inserts documents into an Azure Cosmos DB container, while maintaining a materialized view of the container using Change Feed.
4
-
author: anfeldma
3
+
description: This guide walks you through a simple Java SQL API application which inserts documents into an Azure Cosmos DB container, while maintaining a materialized view of the container using Change Feed.
4
+
author: anfeldma-ms
5
5
ms.service: cosmos-db
6
6
ms.subservice: cosmosdb-sql
7
7
ms.devlang: java
@@ -10,7 +10,7 @@ ms.date: 05/08/2020
10
10
ms.author: anfeldma
11
11
---
12
12
13
-
# How to create a Java application that uses Azure Cosmos DB SQL API and Change Feed Processor
13
+
# How to create a Java application that uses Azure Cosmos DB SQL API and change feed processor
14
14
15
15
> [!IMPORTANT]
16
16
> For more information on Azure Cosmos DB Java SDK v4, please view the Azure Cosmos DB Java SDK v4 Release notes, [Maven repository](https://mvnrepository.com/artifact/com.azure/azure-cosmos), Azure Cosmos DB Java SDK v4 [performance tips](performance-tips-java-sdk-v4-sql.md), and Azure Cosmos DB Java SDK v4 [troubleshooting guide](troubleshoot-java-sdk-v4-sql.md).
@@ -28,11 +28,11 @@ This how-to guide walks you through a simple Java application which uses the Azu
28
28
29
29
## Background
30
30
31
-
The Azure Cosmos DB Change Feed provides an event-driven interface to trigger actions in response to document insertion. This has many uses. For example in applications which are both read and write heavy, a chief use of Change Feed is to create a real-time **materialized view** of a container as it is ingesting documents. The materialized view container will hold the same data but partitioned for efficient reads, making the application both read and write efficient.
31
+
The Azure Cosmos DB change feed provides an event-driven interface to trigger actions in response to document insertion. This has many uses. For example in applications which are both read and write heavy, a chief use of change feed is to create a real-time **materialized view** of a container as it is ingesting documents. The materialized view container will hold the same data but partitioned for efficient reads, making the application both read and write efficient.
32
32
33
-
The work of managing Change Feed events is largely taken care of by the Change Feed Processor library built into the SDK. This library is powerful enough to distribute Change Feed events among multiple workers, if that is desired. All you have to do is provide the Change Feed library a callback.
33
+
The work of managing change feed events is largely taken care of by the change feed Processor library built into the SDK. This library is powerful enough to distribute change feed events among multiple workers, if that is desired. All you have to do is provide the change feed library a callback.
34
34
35
-
This simple example demonstrates Change Feed Processor library with a single worker creating and deleting documents from a materialized view.
35
+
This simple example demonstrates change feed Processor library with a single worker creating and deleting documents from a materialized view.
36
36
37
37
## Setup
38
38
@@ -70,7 +70,7 @@ mvn clean package
70
70
71
71
***InventoryContainer** - The inventory record for our example grocery store, partitioned on item ```id``` which is a UUID.
72
72
***InventoryContainer-pktype** - A materialized view of the inventory record, optimized for queries over item ```type```
73
-
***InventoryContainer-leases** - A leases container is always needed forChange Feed; leases track the app's progressin reading the Change Feed.
73
+
***InventoryContainer-leases** - A leases container is always needed forchange feed; leases track the app's progressin reading the change feed.
Press enter to start creating the materialized view...
83
83
```
84
84
85
-
Press enter. Now the following block of code will execute and initialize the Change Feed processor on another thread:
85
+
Press enter. Now the following block of code will execute and initialize the change feed processor on another thread:
86
86
87
87
### <a id="java4-connection-policy-async"></a>Java SDK V4 (Maven com.azure::azure-cosmos) Async API
88
88
@@ -95,7 +95,7 @@ mvn clean package
95
95
})
96
96
.subscribe();
97
97
98
-
while (!isProcessorRunning.get()); //Wait forChange Feed processor start
98
+
while (!isProcessorRunning.get()); //Wait forchange feed processor start
99
99
```
100
100
101
101
```"SampleHost_1"``` is the name of the Change Feed processor worker. ```changeFeedProcessorInstance.start()``` is what actually starts the Change Feed processor.
1. Press enter again in the terminal. This will trigger 10 documents to be inserted into **InventoryContainer**. Each document insertion appears in the Change Feed as JSON; the following callback code handles these events by mirroring the JSON documents into a materialized view:
107
+
1. Press enter again in the terminal. This will trigger 10 documents to be inserted into **InventoryContainer**. Each document insertion appears in the change feed as JSON; the following callback code handles these events by mirroring the JSON documents into a materialized view:
108
108
109
109
### <a id="java4-connection-policy-async"></a>Java SDK V4 (Maven com.azure::azure-cosmos) Async API
1. Now, in Data Explorer navigate to **InventoryContainer-pktype > items**. This is the materialized view - the items in this container mirror **InventoryContainer** because they were inserted programmatically by Change Feed. Note the partition key (```type```). So this materialized view is optimized for queries filtering over ```type```, which would be inefficient on **InventoryContainer** because it is partitioned on ```id```.
140
+
1. Now, in Data Explorer navigate to **InventoryContainer-pktype > items**. This is the materialized view - the items in this container mirror **InventoryContainer** because they were inserted programmatically by change feed. Note the partition key (```type```). So this materialized view is optimized for queries filtering over ```type```, which would be inefficient on **InventoryContainer** because it is partitioned on ```id```.
The Change Feed```feedPollDelay``` is set to 100ms; therefore, Change Feed responds to this update almost instantly and calls ```updateInventoryTypeMaterializedView()``` shown above. That last functioncall will upsert the new document with TTL of 5sec into **InventoryContainer-pktype**.
179
+
The change feed```feedPollDelay``` is set to 100ms; therefore, change feed responds to this update almost instantly and calls ```updateInventoryTypeMaterializedView()``` shown above. That last functioncall will upsert the new document with TTL of 5sec into **InventoryContainer-pktype**.
180
180
181
181
The effect is that after about 5 seconds, the document will expire and be deleted from both containers.
182
182
183
-
This procedure is necessary because Change Feed only issues events on item insertion or update, not on item deletion.
183
+
This procedure is necessary because change feed only issues events on item insertion or update, not on item deletion.
184
184
185
185
1. Press enter one more time to close the program and clean up its resources.
0 commit comments