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
+19-19Lines changed: 19 additions & 19 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,18 +1,18 @@
1
1
---
2
-
title: Tutorial - an end-to-end Async Java SQL API application sample with Change Feed
3
-
description: This tutorial 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.
2
+
title: Use change feed with an Async Java SQL API application in Azure Cosmos DB
3
+
description: Learn how to use develop a Async 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
4
author: anfeldma
5
5
ms.service: cosmos-db
6
6
ms.subservice: cosmosdb-sql
7
7
ms.devlang: java
8
-
ms.topic: tutorial
9
-
ms.date: 04/01/2020
8
+
ms.topic: conceptual
9
+
ms.date: 05/07/2020
10
10
ms.author: anfeldma
11
11
---
12
12
13
-
# Tutorial - an end-to-end Async Java SQL API application sample with Change Feed
13
+
# How to use change feed with an Async Java SQL API application in Azure Cosmos DB
14
14
15
-
This tutorial 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.
15
+
This tutorial 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.
16
16
17
17
## Prerequisites
18
18
@@ -26,11 +26,11 @@ This tutorial guide walks you through a simple Java SQL API application which in
26
26
27
27
## Background
28
28
29
-
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.
29
+
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.
30
30
31
-
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.
31
+
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.
32
32
33
-
This simple example demonstrates Change Feed Processor library with a single worker creating and deleting documents from a materialized view.
33
+
This simple example demonstrates change feed Processor library with a single worker creating and deleting documents from a materialized view.
34
34
35
35
## Setup
36
36
@@ -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
# [Java SDK 4.0](#tab/v4sdk)
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
# [Java SDK 3.7.0](#tab/v3sdk)
@@ -109,17 +109,17 @@ mvn clean package
109
109
})
110
110
.subscribe();
111
111
112
-
while (!isProcessorRunning.get()); //Wait forChange Feed processor start
112
+
while (!isProcessorRunning.get()); //Wait forchange feed processor start
113
113
```
114
114
---
115
115
116
-
```"SampleHost_1"``` is the name of the Change Feed processor worker. ```changeFeedProcessorInstance.start()``` is what actually starts the Change Feed processor.
116
+
```"SampleHost_1"``` is the name of the change feed processor worker. ```changeFeedProcessorInstance.start()``` is what actually starts the change feed processor.
117
117
118
-
Return to the Azure Portal Data Explorer in your browser. Under the **InventoryContainer-leases** container, click **items** to see its contents. You will see that Change Feed Processor has populated the lease container, i.e. the processor has assigned the ```SampleHost_1``` worker a lease on some partitions of the **InventoryContainer**.
118
+
Return to the Azure Portal Data Explorer in your browser. Under the **InventoryContainer-leases** container, click **items** to see its contents. You will see that change feed Processor has populated the lease container, i.e. the processor has assigned the ```SampleHost_1``` worker a lease on some partitions of the **InventoryContainer**.
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:
122
+
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:
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```.
183
+
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**.
251
+
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**.
252
252
253
253
The effect is that after about 5 seconds, the document will expire and be deleted from both containers.
254
254
255
-
This procedure is necessary because Change Feed only issues events on item insertion or update, not on item deletion.
255
+
This procedure is necessary because change feed only issues events on item insertion or update, not on item deletion.
256
256
257
257
1. Press enter one more time to close the program and clean up its resources.
0 commit comments