From 90e6285d7e6e2c3f3d9f6528dd14ab3d169cca1a Mon Sep 17 00:00:00 2001 From: Sidney Andrews Date: Tue, 27 Sep 2022 11:31:18 -0400 Subject: [PATCH] Theo's changes --- README.md | 6 +- demos/cosmos-db/demo/pom.xml | 5 -- .../demo/config/CosmosConfiguration.java | 28 ++++++- .../demo/config/DocumentDbConfiguration.java | 75 ------------------ .../demo/controller/BulkController.java | 15 ++-- .../example/demo/model/BulkDeleteItem.java | 15 ---- .../example/demo/model/BulkUpdateItem.java | 24 ------ .../demo/model/BulkUpdateOperation.java | 22 ------ .../demo/service/BulkExecutorService.java | 78 +++++++++---------- .../static/Cosmosdb.postman_collection.json | 10 +-- docs/_config.yml | 2 +- docs/_layouts/home.html | 3 +- docs/bulk-executor.md | 47 +++-------- docs/foreword.md | 10 +-- docs/get-started-with-java-and-cosmos-db.md | 4 +- docs/index.md | 8 +- 16 files changed, 98 insertions(+), 254 deletions(-) delete mode 100644 demos/cosmos-db/demo/src/main/java/com/example/demo/config/DocumentDbConfiguration.java delete mode 100644 demos/cosmos-db/demo/src/main/java/com/example/demo/model/BulkDeleteItem.java delete mode 100644 demos/cosmos-db/demo/src/main/java/com/example/demo/model/BulkUpdateItem.java delete mode 100644 demos/cosmos-db/demo/src/main/java/com/example/demo/model/BulkUpdateOperation.java diff --git a/README.md b/README.md index 7e8034e..af08368 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ -# Cloud-Scale Data for Spring Developers Guide +# Cloud-Scale Data for Spring Developers > Java + Azure Cosmos DB + Azure Spring Apps + Azure Functions + Azure Cognitive Search + more! -![Screenshot of book cover featuring title, an illustration of developer tools, the Azure Cosmos DB logo, a subtitle, and a version moniker. In this screenshot, the title is "Azure Cosmos DB Java Developers Guide", the subtitle is "Bring cloud-native Java applications to Azure using Azure Cosmos DB SQL API", and the version is "1.0".](docs/media/index/cover.svg) +![Screenshot of book cover featuring title, an illustration of developer tools, the Azure Cosmos DB logo, a subtitle, and a version moniker. In this screenshot, the title is "Cloud-Scale Data for Spring Developers", the subtitle is "Bring cloud-native Java applications to Azure using Azure Cosmos DB SQL API", and the version is "1.0".](docs/media/index/cover.svg) [Get started reading the guide!](docs/index.md) @@ -24,4 +24,4 @@ contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additio This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft trademarks or logos is subject to and must follow [Microsoft's Trademark & Brand Guidelines](https://www.microsoft.com/en-us/legal/intellectualproperty/trademarks/usage/general). Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship. -Any use of third-party trademarks or logos are subject to those third-party's policies. +Any use of third-party trademarks or logos are subject to those third-party's policies. \ No newline at end of file diff --git a/demos/cosmos-db/demo/pom.xml b/demos/cosmos-db/demo/pom.xml index 4dbb903..0b51d9a 100644 --- a/demos/cosmos-db/demo/pom.xml +++ b/demos/cosmos-db/demo/pom.xml @@ -55,11 +55,6 @@ azure-cosmos 4.22.0 - - com.microsoft.azure - documentdb-bulkexecutor - 2.12.5 - org.springframework.boot spring-boot-devtools diff --git a/demos/cosmos-db/demo/src/main/java/com/example/demo/config/CosmosConfiguration.java b/demos/cosmos-db/demo/src/main/java/com/example/demo/config/CosmosConfiguration.java index eb421b5..1bb521b 100644 --- a/demos/cosmos-db/demo/src/main/java/com/example/demo/config/CosmosConfiguration.java +++ b/demos/cosmos-db/demo/src/main/java/com/example/demo/config/CosmosConfiguration.java @@ -14,9 +14,11 @@ import com.azure.spring.data.cosmos.core.ResponseDiagnostics; import com.azure.spring.data.cosmos.core.ResponseDiagnosticsProcessor; import com.azure.spring.data.cosmos.repository.config.EnableCosmosRepositories; import com.fasterxml.jackson.databind.JsonNode; - import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Primary; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; import org.springframework.lang.Nullable; @@ -41,6 +43,12 @@ public class CosmosConfiguration extends AbstractCosmosConfiguration { @Value("${azure.cosmos.lease-container}") private String leaseContainer; + private CosmosAsyncClient client; + private CosmosAsyncDatabase database; + private CosmosAsyncContainer container; + + private static final Logger logger = LoggerFactory.getLogger(CosmosConfiguration.class); + public CosmosConfiguration() {} @Bean @@ -73,6 +81,24 @@ public class CosmosConfiguration extends AbstractCosmosConfiguration { }); } + @Primary + @Bean + public CosmosAsyncClient getClient(){ + return client = getCosmosClientBuilder().buildAsyncClient(); + } + + @Bean + public CosmosAsyncDatabase CosmosDatabaseBuilder() { + database = client.getDatabase(this.dbName); + return database; + } + + @Bean + public CosmosAsyncContainer CosmosContainerBuilder() { + container = database.getContainer(this.feedContainer); + return container; + } + @Override public CosmosConfig cosmosConfig() { return CosmosConfig.builder() diff --git a/demos/cosmos-db/demo/src/main/java/com/example/demo/config/DocumentDbConfiguration.java b/demos/cosmos-db/demo/src/main/java/com/example/demo/config/DocumentDbConfiguration.java deleted file mode 100644 index 9c71f4c..0000000 --- a/demos/cosmos-db/demo/src/main/java/com/example/demo/config/DocumentDbConfiguration.java +++ /dev/null @@ -1,75 +0,0 @@ -package com.example.demo.config; - -import com.microsoft.azure.documentdb.ConnectionPolicy; -import com.microsoft.azure.documentdb.ConsistencyLevel; -import com.microsoft.azure.documentdb.DocumentClient; -import com.microsoft.azure.documentdb.DocumentClientException; -import com.microsoft.azure.documentdb.DocumentCollection; -import com.microsoft.azure.documentdb.ResourceResponse; -import com.microsoft.azure.documentdb.bulkexecutor.DocumentBulkExecutor; -import com.microsoft.azure.documentdb.bulkexecutor.DocumentBulkExecutor.Builder; - -import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -@Configuration -public class DocumentDbConfiguration { - - private static final Logger LOGGER = LoggerFactory.getLogger(CosmosConfiguration.class); - - @Value("${azure.cosmos.uri}") - private String uri; - - @Value("${azure.cosmos.key}") - private String key; - - @Value("${azure.cosmos.database}") - private String dbName; - - @Value("${azure.cosmos.collection}") - private String collectionName; - - @Value("${azure.cosmos.partitionKey}") - private String partitionKey; - - - @Bean - public DocumentClient getDocumentClient() { - ConnectionPolicy cPolicy = new ConnectionPolicy(); - cPolicy.setMaxPoolSize(1000); - return new DocumentClient(uri, key, cPolicy, ConsistencyLevel.Session); - } - - public static DocumentCollection getDocumentCollection(DocumentClient client, String databaseId, String collectionId) { - String collectionLink = String.format("/dbs/%s/colls/%s", databaseId, collectionId); - DocumentCollection collection = null; - try { - ResourceResponse collectionResponse = client.readCollection(collectionLink, null); - collection = collectionResponse.getResource(); - } catch (DocumentClientException dce) { - LOGGER.error("Error getting collection", dce); - } - return collection; - } - - @Bean - public Builder getBulkExecutorBuilder() { - DocumentClient client = getDocumentClient(); - - client.getConnectionPolicy().getRetryOptions().setMaxRetryWaitTimeInSeconds(30); - client.getConnectionPolicy().getRetryOptions().setMaxRetryAttemptsOnThrottledRequests(9); - DocumentCollection collection = getDocumentCollection(client, dbName, collectionName); - - return DocumentBulkExecutor.builder() - .from( - client, - dbName, - collection.getId(), - collection.getPartitionKey(), - 1000 - ); - } -} \ No newline at end of file diff --git a/demos/cosmos-db/demo/src/main/java/com/example/demo/controller/BulkController.java b/demos/cosmos-db/demo/src/main/java/com/example/demo/controller/BulkController.java index 0d9dbfb..5770ebb 100644 --- a/demos/cosmos-db/demo/src/main/java/com/example/demo/controller/BulkController.java +++ b/demos/cosmos-db/demo/src/main/java/com/example/demo/controller/BulkController.java @@ -2,14 +2,9 @@ package com.example.demo.controller; import java.util.List; +import com.azure.cosmos.models.CosmosBulkItemResponse; import com.example.demo.model.BaseModel; -import com.example.demo.model.BulkDeleteItem; -import com.example.demo.model.BulkUpdateItem; import com.example.demo.service.BulkExecutorService; -import com.microsoft.azure.documentdb.bulkexecutor.BulkDeleteResponse; -import com.microsoft.azure.documentdb.bulkexecutor.BulkImportResponse; -import com.microsoft.azure.documentdb.bulkexecutor.BulkUpdateResponse; - import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.PostMapping; @@ -26,17 +21,17 @@ public class BulkController { BulkExecutorService bulkExecutorService; @PostMapping(produces = "application/json", consumes = "application/json") - public BulkImportResponse create(@RequestBody List documents) { + public CosmosBulkItemResponse create(@RequestBody List documents) { return this.bulkExecutorService.bulkImport(documents); } @PutMapping(produces = "application/json", consumes = "application/json") - public BulkUpdateResponse update(@RequestBody List updates) { + public CosmosBulkItemResponse update(@RequestBody List updates) { return this.bulkExecutorService.bulkUpdate(updates); } @DeleteMapping(produces = "application/json", consumes = "application/json") - public BulkDeleteResponse delete(@RequestBody List deleteItems){ + public CosmosBulkItemResponse delete(@RequestBody List deleteItems){ return this.bulkExecutorService.bulkDelete(deleteItems); } -} +} \ No newline at end of file diff --git a/demos/cosmos-db/demo/src/main/java/com/example/demo/model/BulkDeleteItem.java b/demos/cosmos-db/demo/src/main/java/com/example/demo/model/BulkDeleteItem.java deleted file mode 100644 index 6948f50..0000000 --- a/demos/cosmos-db/demo/src/main/java/com/example/demo/model/BulkDeleteItem.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.example.demo.model; - -import org.apache.commons.lang3.tuple.Pair; - -import lombok.*; - -@Getter @Setter @NoArgsConstructor -public class BulkDeleteItem { - private String partitionKey; - private String id; - - public Pair toPair(){ - return Pair.of(partitionKey, id); - } -} diff --git a/demos/cosmos-db/demo/src/main/java/com/example/demo/model/BulkUpdateItem.java b/demos/cosmos-db/demo/src/main/java/com/example/demo/model/BulkUpdateItem.java deleted file mode 100644 index 1af5584..0000000 --- a/demos/cosmos-db/demo/src/main/java/com/example/demo/model/BulkUpdateItem.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.example.demo.model; - -import java.util.List; -import java.util.stream.Collectors; - -import com.microsoft.azure.documentdb.bulkexecutor.UpdateItem; -import com.microsoft.azure.documentdb.bulkexecutor.UpdateOperationBase; - - -import lombok.*; - -@Getter @Setter @NoArgsConstructor -public class BulkUpdateItem { - - private String id; - private String partitionKey; - private List operations; - - public UpdateItem ToUpdateItem() { - List updateOperations = operations.stream().map(BulkUpdateOperation::toUpdateOperation) - .collect(Collectors.toList()); - return new UpdateItem(id, partitionKey, updateOperations); - } -} diff --git a/demos/cosmos-db/demo/src/main/java/com/example/demo/model/BulkUpdateOperation.java b/demos/cosmos-db/demo/src/main/java/com/example/demo/model/BulkUpdateOperation.java deleted file mode 100644 index bd412d9..0000000 --- a/demos/cosmos-db/demo/src/main/java/com/example/demo/model/BulkUpdateOperation.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.example.demo.model; - -import com.microsoft.azure.documentdb.bulkexecutor.SetUpdateOperation; -import com.microsoft.azure.documentdb.bulkexecutor.internal.UpdateOperation; -import com.microsoft.azure.documentdb.bulkexecutor.internal.UpdateOperationType; -import lombok.*; - -@Getter @Setter @NoArgsConstructor -public class BulkUpdateOperation { - - private UpdateOperationType type; - private String field; - private Object value; - - public UpdateOperation toUpdateOperation() { - //TODO define the UpdateOperationTypes so they implement the appropriate subclass - switch(type) { - default: - return new SetUpdateOperation(field, value); - } - } -} diff --git a/demos/cosmos-db/demo/src/main/java/com/example/demo/service/BulkExecutorService.java b/demos/cosmos-db/demo/src/main/java/com/example/demo/service/BulkExecutorService.java index f2ae5e7..d392115 100644 --- a/demos/cosmos-db/demo/src/main/java/com/example/demo/service/BulkExecutorService.java +++ b/demos/cosmos-db/demo/src/main/java/com/example/demo/service/BulkExecutorService.java @@ -1,48 +1,48 @@ package com.example.demo.service; import java.util.List; -import java.util.stream.Collectors; import com.example.demo.model.BaseModel; -import com.example.demo.model.BulkDeleteItem; -import com.example.demo.model.BulkUpdateItem; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.microsoft.azure.documentdb.bulkexecutor.BulkDeleteResponse; -import com.microsoft.azure.documentdb.bulkexecutor.BulkImportResponse; -import com.microsoft.azure.documentdb.bulkexecutor.BulkUpdateResponse; -import com.microsoft.azure.documentdb.bulkexecutor.DocumentBulkExecutor; -import com.microsoft.azure.documentdb.bulkexecutor.UpdateItem; -import com.microsoft.azure.documentdb.bulkexecutor.DocumentBulkExecutor.Builder; -import org.springframework.beans.factory.annotation.Autowired; +import reactor.core.publisher.Flux; + import org.springframework.stereotype.Component; -import org.apache.commons.lang3.tuple.Pair; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.azure.cosmos.CosmosAsyncClient; +import com.azure.cosmos.CosmosAsyncContainer; +import com.azure.cosmos.CosmosAsyncDatabase; +import com.azure.cosmos.models.*; + @Component public class BulkExecutorService { private static final Logger LOGGER = LoggerFactory.getLogger(BulkExecutorService.class); - @Autowired - Builder builder; - - @Autowired + CosmosAsyncClient client; + CosmosAsyncDatabase database; + CosmosAsyncContainer container; ObjectMapper mapper; - public BulkDeleteResponse bulkDelete(List deleteItems) { - BulkDeleteResponse response = null; - try (DocumentBulkExecutor bExecutor = builder.build()) { - List> pksAndIds = deleteItems.stream().map(BulkDeleteItem::toPair).collect(Collectors.toList()); - response = bExecutor.deleteAll(pksAndIds); - } catch (Exception ex) { - LOGGER.error("Error bulk deleting", ex); - } - return response; + //favouring constructor dependency injection + public BulkExecutorService(CosmosAsyncClient client, CosmosAsyncDatabase database, CosmosAsyncContainer container, ObjectMapper mapper){ + this.client = client; + this.database = database; + this.container = container; + this.mapper = mapper; } + public CosmosBulkItemResponse bulkDelete(List deleteItems) { + Flux docs = Flux.fromIterable(deleteItems); + Flux cosmosItemOperations = docs.map( + document -> CosmosBulkOperations + .getDeleteItemOperation(document.getId(), new PartitionKey(document.getDocumentType()))); + return container.executeBulkOperations(cosmosItemOperations).blockLast().getResponse(); + } + private String serialize(BaseModel model) { String rawJson = null; try { @@ -54,25 +54,17 @@ public class BulkExecutorService { return rawJson; } - public BulkImportResponse bulkImport(List documents) { - BulkImportResponse response = null; - List convertedDocuments = documents.stream().map(this::serialize).collect(Collectors.toList()); - try (DocumentBulkExecutor bExecutor = builder.build()) { - response = bExecutor.importAll(convertedDocuments, true, true, null); - } catch (Exception ex) { - LOGGER.error("Error bulk importing", ex); - } - return response; + public CosmosBulkItemResponse bulkImport(List documents) { + Flux docs = Flux.fromIterable(documents); + Flux cosmosItemOperations = docs.map( + document -> CosmosBulkOperations.getUpsertItemOperation(document, new PartitionKey(document.getDocumentType()))); + return container.executeBulkOperations(cosmosItemOperations).blockLast().getResponse(); } - public BulkUpdateResponse bulkUpdate(List updateItems) { - BulkUpdateResponse response = null; - List updates = updateItems.stream().map(BulkUpdateItem::ToUpdateItem).collect(Collectors.toList()); - try (DocumentBulkExecutor bExecutor = builder.build()) { - response = bExecutor.updateAll(updates, null); - } catch (Exception ex) { - LOGGER.error("Error bulk updating", ex); - } - return response; + public CosmosBulkItemResponse bulkUpdate(List updateItems) { + Flux docs = Flux.fromIterable(updateItems); + Flux cosmosItemOperations = docs.map( + document -> CosmosBulkOperations.getUpsertItemOperation(document, new PartitionKey(document.getDocumentType()))); + return container.executeBulkOperations(cosmosItemOperations).blockLast().getResponse(); } -} +} \ No newline at end of file diff --git a/demos/cosmos-db/demo/src/main/resources/static/Cosmosdb.postman_collection.json b/demos/cosmos-db/demo/src/main/resources/static/Cosmosdb.postman_collection.json index e560b45..04c2695 100644 --- a/demos/cosmos-db/demo/src/main/resources/static/Cosmosdb.postman_collection.json +++ b/demos/cosmos-db/demo/src/main/resources/static/Cosmosdb.postman_collection.json @@ -1,6 +1,6 @@ { "info": { - "_postman_id": "83930195-5591-49b9-ab8f-fd8d6aeaaad7", + "_postman_id": "3c5e7df1-124e-4450-bbd0-9bbcc15e0cf8", "name": "Cosmosdb", "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json" }, @@ -15,7 +15,7 @@ "header": [], "body": { "mode": "raw", - "raw": "{\r\n \"type\": \"test type\",\r\n \"name\": \"test name\",\r\n \"description\": \"test description\",\r\n \"manufacturerId\": \"test manufacturer\",\r\n \"msrp\": 10.00\r\n}", + "raw": "{\r\n \"type\": \"test type\",\r\n \"documentType\": \"product\",\r\n \"name\": \"test name\",\r\n \"description\": \"test description\",\r\n \"manufacturerId\": \"test manufacturer\",\r\n \"msrp\": 10.00\r\n}", "options": { "raw": { "language": "json" @@ -612,7 +612,7 @@ "header": [], "body": { "mode": "raw", - "raw": "[\n { \n \"partitionKey\":\"product\", \n \"id\": \"4e33d133-3490-4fe0-944a-cbffaab96ec2\" \n }\n]", + "raw": "[\n {\n \"id\": \"1\",\n \"documentType\": \"product\"\n },\n {\n \"id\": \"2\",\n \"documentType\": \"customer\"\n },\n {\n \"id\": \"3\",\n \"documentType\": \"manufacturer\"\n }\n]", "options": { "raw": { "language": "json" @@ -641,7 +641,7 @@ "header": [], "body": { "mode": "raw", - "raw": "[\n { \n \"documentType\": \"product\",\n \"type\": \"bulk product type\",\n \"name\": \"bulk product #1\",\n \"description\": \"products imported in bulk\",\n \"manufacturerId\": \"d73154c6-c657-4c81-b97a-756de35819ef\",\n \"msrp\": 100\n },\n {\n \"documentType\": \"customer\",\n \"firstName\": \"Bulk Customer\",\n \"lastName\": \"Number 1\",\n \"email\": \"customer@example.demo\"\n },\n {\n \"documentType\": \"manufacturer\",\n \"name\": \"bulk manufacturer #1\"\n }\n]", + "raw": "[\n {\n \"id\": \"1\",\n \"documentType\": \"product\",\n \"type\": \"bulk product type\",\n \"name\": \"bulk product #1\",\n \"description\": \"products imported in bulk\",\n \"manufacturerId\": \"d73154c6-c657-4c81-b97a-756de35819ef\",\n \"msrp\": 100\n },\n {\n \"id\": \"2\",\n \"documentType\": \"customer\",\n \"firstName\": \"Bulk Customer\",\n \"lastName\": \"Number 1\",\n \"email\": \"customer@example.demo\"\n },\n {\n \"id\": \"3\",\n \"documentType\": \"manufacturer\",\n \"name\": \"bulk manufacturer #1\"\n }\n]", "options": { "raw": { "language": "json" @@ -670,7 +670,7 @@ "header": [], "body": { "mode": "raw", - "raw": "[\n {\n \"id\": \"684a1471-4ec2-44cb-bc8b-0cc8604eed30\",\n \"partitionKey\": \"product\",\n \"operations\": [\n {\n \"type\": \"Set\",\n \"field\": \"name\",\n \"value\": \"derp\"\n }\n ]\n\n }\n]", + "raw": "[\n {\n \"id\": \"1\",\n \"documentType\": \"product\",\n \"type\": \"bulk product type\",\n \"name\": \"bulk product #1\",\n \"description\": \"products bulk updated\",\n \"manufacturerId\": \"d73154c6-c657-4c81-b97a-756de35819ef\",\n \"msrp\": 100\n },\n {\n \"id\": \"2\",\n \"documentType\": \"customer\",\n \"firstName\": \"Bulk Update Customer\",\n \"lastName\": \"Number 1\",\n \"email\": \"customer@example.demo\"\n },\n {\n \"id\": \"3\",\n \"documentType\": \"manufacturer\",\n \"name\": \"bulk update manufacturer #1\"\n }\n]", "options": { "raw": { "language": "json" diff --git a/docs/_config.yml b/docs/_config.yml index 9069605..ad79cf2 100644 --- a/docs/_config.yml +++ b/docs/_config.yml @@ -1,6 +1,6 @@ theme: jekyll-theme-cayman title: | - Azure Cosmos DB Java Developer Guide + Cloud-Scale Data for Spring Developers description: | Java + Azure Cosmos DB + Azure Spring Apps + Azure Functions + Azure Cognitive Search + more! exclude: diff --git a/docs/_layouts/home.html b/docs/_layouts/home.html index c813d33..0444148 100644 --- a/docs/_layouts/home.html +++ b/docs/_layouts/home.html @@ -16,8 +16,7 @@ layout: default
+ Screenshot of book cover featuring title, an illustration of developer tools, the Azure Cosmos DB logo, a subtitle, and a version moniker. In this screenshot, the title is 'Cloud-Scale Data for Spring Developers', the subtitle is 'Bring cloud-native Java applications to Azure using Azure Cosmos DB SQL API', and the version is '1.0'.
{{ content }}
diff --git a/docs/bulk-executor.md b/docs/bulk-executor.md index 244c7a3..ea1582b 100644 --- a/docs/bulk-executor.md +++ b/docs/bulk-executor.md @@ -10,29 +10,14 @@ ms.reviewer: mjbrown sequence: 13 --- -# Add the bulk executor feature +# Bulk Execution - The bulk executor is an Azure Cosmos DB feature that allows bulk inserts, updates, and deletes. When inserts and updates occur, they appear in the change feed. + Bulk Execution is an Azure Cosmos DB feature that allows bulk inserts, updates, and deletes. When inserts and updates occur, they appear in the change feed. Bulk Execution is part of the Java V4 SDK for Azure Cosmos DB. -The following sections incorporate the bulk executor into the code sample. - -## Add a dependency - -Add a new dependency in the *pom.xml* file: - -```xml - - com.microsoft.azure - documentdb-bulkexecutor - 2.12.5 - -``` - -Add to the Spring Data setup by creating a `DocumentDbConfiguration` class specifically for use with the bulk executor. ## Add application properties -Add bulk executer details to the *application-default.properties* file: +Add details of the collection where bulk execution will be used to the *application-default.properties* file: ```properties # values for bulk executor @@ -43,30 +28,18 @@ azure.cosmos.collectionThroughput = 100000; ## Update code -Most of the bulk operations occur in `BulkExecutorService`. Each operation is in its own class file: +All bulk operations occur in `BulkExecutorService`. -- `BulkUpdateOperation` +A controller calls the bulk operations, with the following endpoints: -- `BulkDeleteItem` +- `/api/bulk POST`: Bulk import +- `/api/bulk PUT`: Bulk update +- `/api/bulk DELETE`: Bulk delete -- `BulkUpdateItem` - -- `BulkExecutorService` - -Update your code as follows: - -1. Update your models to inherit from a `BaseModel` class. - -1. Add a controller to call the bulk operations, with the following endpoints: - - - `/api/bulk POST`: Bulk import - - `/api/bulk PUT`: Bulk update - - `/api/bulk DELETE`: Bulk delete - -In the Postman collection, we've included a section for you to try each of these bulk operations against the sample code. +In the Postman collection, we've included a section for you to try each of these bulk operations against the sample code. ## Learn more [Azure Cosmos DB bulk executor library overview](https://docs.microsoft.com/azure/cosmos-db/bulk-executor-overview) -[Next | Schema design considerations](schema-considerations.md){: .btn .btn-primary .btn-lg } +[Next | Schema design considerations](schema-considerations.md){: .btn .btn-primary .btn-lg } \ No newline at end of file diff --git a/docs/foreword.md b/docs/foreword.md index b627ff9..613c337 100644 --- a/docs/foreword.md +++ b/docs/foreword.md @@ -1,5 +1,5 @@ --- -title: Cloud-Scale Data for Spring Developers Guide +title: Cloud-Scale Data for Spring Developers description: Learn how the Cloud-Scale Data for Spring Developers Quick Start Guide can help you bring cloud-native Java applications to Azure. ms.service: cosmos-db ms.topic: reference @@ -10,9 +10,9 @@ ms.reviewer: mjbrown sequence: 0 --- -# Cloud-Scale Data for Spring Developers Guide: Foreword +# Cloud-Scale Data for Spring Developers Quickstart guide: Foreword -Welcome to the Cloud-Scale Data for Spring Developers Developer Quick Start Guide. The purpose of this guide is to help you build cloud-native Java applications in Azure. You'll gain insights about using NoSQL and why you should consider Azure Cosmos DB, our fully managed, distributed NoSQL database service on Azure. +Welcome to the Cloud-Scale for Spring Developers Quick Start Guide. The purpose of this guide is to help you build cloud-native Java applications in Azure. You'll gain insights about using NoSQL and why you should consider Azure Cosmos DB, our fully managed, distributed NoSQL database service on Azure. These insights are designed to be useful whether you're starting with a NoSQL background or coming into a project with a relational mindset. Data isn't the only thing involved in an application, and this guide will take you through working with other Azure services that integrate well with Azure Cosmos DB. @@ -28,7 +28,7 @@ Retail situations will be included, as well as suggestions for other business ca ## Not covered -This guide doesn't explain how to migrate existing Java applications to Azure. Migrating existing Java applications is covered in the [Java to Azure migration strategy documentation](/azure/developer/java/migration/). As well, this guide doesn't cover relational data storage in Azure. It isn't intended to be a complete compendium of all things Java and Azure, though there will be many Azure offerings showcased. +This guide doesn't explain how to migrate existing Java applications to Azure. Migrating existing Java applications is covered in the [Java to Azure migration strategy documentation](/azure/developer/java/migration/). As well, this guide doesn't cover relational data storage in Azure. It isn't intended to be a complete compendium of all things Java and Azure, though there will be many Azure offerings showcased. The guide also does not offer a complete coverage of the Java SDK for Azure Cosmos DB, or the wider Java ecosystem for Azure Cosmos DB. It is not intended as a comprehensive recommendation for how to build *any* Java app using Azure Cosmos DB, but rather as a guide for how to get started with Spring Boot, featuring the `azure-spring-boot-starter-cosmos` library, as well as coverage of some core Java V4 SDK features and concepts. ## Scenario introduction @@ -44,4 +44,4 @@ Start building your next Java app with Azure by taking advantage of the free app * Azure Functions with up to 1M requests for free * Azure Cognitive Services up to 30,000 transactions free -[Next | Introduction to NoSQL](intro-nosql.md){: .btn .btn-primary .btn-lg } +[Next | Introduction to NoSQL](intro-nosql.md){: .btn .btn-primary .btn-lg } \ No newline at end of file diff --git a/docs/get-started-with-java-and-cosmos-db.md b/docs/get-started-with-java-and-cosmos-db.md index dd7682a..8351f2d 100644 --- a/docs/get-started-with-java-and-cosmos-db.md +++ b/docs/get-started-with-java-and-cosmos-db.md @@ -127,7 +127,7 @@ There are a few more things you need to set up before you can run your code: ### Clone the repository -Clone the repository that contains the sample code, which is available in the [Azure Cosmos DB Java Developer Guide repository](https://github.com/Azure/azure-cosmos-db-java-dev-guide/tree/main/demos). The repository contains a folder named *demos*, with the following contents: +Clone the repository that contains the sample code, which is available in the [Cloud-Scale Data for Spring Developers repository](https://github.com/Azure/cloud-scale-for-spring-developer/tree/main/demos). The repository contains a folder named *demos*, with the following contents: - hello-world-keyvault: An introduction to Java and Azure Key Vault, which is used to store your application secrets securely. @@ -184,4 +184,4 @@ mvn spring-boot:run - [Partition Strategy - Azure Cosmos DB Essentials, Season 2](https://www.youtube.com/watch?v=QLgK8yhKd5U) -[Next | Deploy to Azure App Service](deploy-to-azure-app-service.md){: .btn .btn-primary .btn-lg } +[Next | Deploy to Azure App Service](deploy-to-azure-app-service.md){: .btn .btn-primary .btn-lg } \ No newline at end of file diff --git a/docs/index.md b/docs/index.md index fc172c9..dd284b2 100644 --- a/docs/index.md +++ b/docs/index.md @@ -1,6 +1,6 @@ --- -title: Cloud-Scale Data for Spring Developers Guide -description: Cloud-Scale Data for Spring Developers is a quick start guide for bringing Cloud Native Java applications to Azure and using Azure Cosmos DB for your data needs. +title: Cloud-Scale Data for Spring Developers +description: The Cloud-Scale Data for Spring Developers Quick Start Guide is a guide for bringing Cloud Native Java applications to Azure and using Azure Cosmos DB for your data needs. ms.service: cosmos-db ms.topic: overview ms.date: 08/19/2022 @@ -9,7 +9,7 @@ ms.author: sidandrews ms.reviewer: mjbrown --- -# Cloud-Scale Data for Spring Developers Guide +# Cloud-Scale Data for Spring Developers ## VERSION v1.0 @@ -35,4 +35,4 @@ Microsoft and the trademarks listed at on the "Trade All other marks and logos are property of their respective owners. -[Next | Foreword](foreword.md){: .btn .btn-primary .btn-lg } +[Next | Foreword](foreword.md){: .btn .btn-primary .btn-lg } \ No newline at end of file