Skip to content

Commit 41e5573

Browse files
committed
SOW
1 parent 64458ce commit 41e5573

File tree

1 file changed

+3
-75
lines changed

1 file changed

+3
-75
lines changed

articles/cosmos-db/create-sql-api-java-changefeed.md

Lines changed: 3 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ mvn clean package
8484

8585
Press enter. Now the following block of code will execute and initialize the Change Feed processor on another thread:
8686

87-
# [Java SDK 4.0](#tab/v4sdk)
87+
### <a id="java4-connection-policy-async"></a>Java SDK V4 (Maven com.azure::azure-cosmos) Async API
8888

8989
```java
9090
changeFeedProcessorInstance = getChangeFeedProcessor("SampleHost_1", feedContainer, leaseContainer);
@@ -98,21 +98,6 @@ mvn clean package
9898
while (!isProcessorRunning.get()); //Wait for Change Feed processor start
9999
```
100100
101-
# [Java SDK 3.7.0](#tab/v3sdk)
102-
103-
```java
104-
changeFeedProcessorInstance = getChangeFeedProcessor("SampleHost_1", feedContainer, leaseContainer);
105-
changeFeedProcessorInstance.start()
106-
.subscribeOn(Schedulers.elastic())
107-
.doOnSuccess(aVoid -> {
108-
isProcessorRunning.set(true);
109-
})
110-
.subscribe();
111-
112-
while (!isProcessorRunning.get()); //Wait for Change Feed processor start
113-
```
114-
---
115-
116101
```"SampleHost_1"``` is the name of the Change Feed processor worker. ```changeFeedProcessorInstance.start()``` is what actually starts the Change Feed processor.
117102
118103
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**.
@@ -121,7 +106,7 @@ mvn clean package
121106
122107
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:
123108
124-
# [Java SDK 4.0](#tab/v4sdk)
109+
### <a id="java4-connection-policy-async"></a>Java SDK V4 (Maven com.azure::azure-cosmos) Async API
125110
126111
```java
127112
public static ChangeFeedProcessor getChangeFeedProcessor(String hostName, CosmosAsyncContainer feedContainer, CosmosAsyncContainer leaseContainer) {
@@ -148,34 +133,6 @@ mvn clean package
148133
}
149134
```
150135
151-
# [Java SDK 3.7.0](#tab/v3sdk)
152-
153-
```java
154-
public static ChangeFeedProcessor getChangeFeedProcessor(String hostName, CosmosContainer feedContainer, CosmosContainer leaseContainer) {
155-
ChangeFeedProcessorOptions cfOptions = new ChangeFeedProcessorOptions();
156-
cfOptions.feedPollDelay(Duration.ofMillis(100));
157-
cfOptions.startFromBeginning(true);
158-
return ChangeFeedProcessor.Builder()
159-
.options(cfOptions)
160-
.hostName(hostName)
161-
.feedContainer(feedContainer)
162-
.leaseContainer(leaseContainer)
163-
.handleChanges((List<CosmosItemProperties> docs) -> {
164-
for (CosmosItemProperties document : docs) {
165-
//Duplicate each document update from the feed container into the materialized view container
166-
updateInventoryTypeMaterializedView(document);
167-
}
168-
169-
})
170-
.build();
171-
}
172-
173-
private static void updateInventoryTypeMaterializedView(CosmosItemProperties document) {
174-
typeContainer.upsertItem(document).subscribe();
175-
}
176-
```
177-
---
178-
179136
1. Allow the code to run 5-10sec. Then return to the Azure Portal Data Explorer and navigate to **InventoryContainer > items**. You should see that items are being inserted into the inventory container; note the partition key (```id```).
180137
181138
![Feed container](media/create-sql-api-java-changefeed/cosmos_items.JPG)
@@ -190,35 +147,7 @@ mvn clean package
190147
191148
Hit enter again to call the function ```deleteDocument()``` in the example code. This function, shown below, upserts a new version of the document with ```/ttl == 5```, which sets document Time-To-Live (TTL) to 5sec.
192149
193-
# [Java SDK 4.0](#tab/v4sdk)
194-
195-
```java
196-
public static void deleteDocument() {
197-
198-
String jsonString = "{\"id\" : \"" + idToDelete + "\""
199-
+ ","
200-
+ "\"brand\" : \"Jerry's\""
201-
+ ","
202-
+ "\"type\" : \"plums\""
203-
+ ","
204-
+ "\"quantity\" : \"50\""
205-
+ ","
206-
+ "\"ttl\" : 5"
207-
+ "}";
208-
209-
ObjectMapper mapper = new ObjectMapper();
210-
JsonNode document = null;
211-
212-
try {
213-
document = mapper.readTree(jsonString);
214-
} catch (Exception e) {
215-
e.printStackTrace();
216-
}
217-
218-
feedContainer.upsertItem(document,new CosmosItemRequestOptions()).block();
219-
}
220-
```
221-
# [Java SDK 3.7.0](#tab/v3sdk)
150+
### <a id="java4-connection-policy-async"></a>Java SDK V4 (Maven com.azure::azure-cosmos) Async API
222151
223152
```java
224153
public static void deleteDocument() {
@@ -246,7 +175,6 @@ mvn clean package
246175
feedContainer.upsertItem(document,new CosmosItemRequestOptions()).block();
247176
}
248177
```
249-
---
250178
251179
The Change Feed ```feedPollDelay``` is set to 100ms; therefore, Change Feed responds to this update almost instantly and calls ```updateInventoryTypeMaterializedView()``` shown above. That last function call will upsert the new document with TTL of 5sec into **InventoryContainer-pktype**.
252180

0 commit comments

Comments
 (0)