Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@
<msal4j.version>1.17.2</msal4j.version>
<!-- @sync com.azure:azure-cosmos:${azure-cosmos.version} dep:com.azure:azure-core-http-netty dep:io.projectreactor.netty:reactor-netty-http -->
<reactor-netty-http.version>1.0.48</reactor-netty-http.version>
<!-- needed for dependency convergence -->
<!-- @sync com.microsoft.azure:msal4j:${msal4j.version} dep:com.nimbusds:oauth2-oidc-sdk dep:net.minidev:json-smart com.microsoft.azure:msal4j:${msal4j.version} dep:net.minidev:json-smart -->
<json-smart.version>2.5.1</json-smart.version>
<!-- @sync com.azure:azure-core-http-vertx:${azure.core.http.client.vertx.version} dep:com.azure:azure-core com.azure:azure-sdk-bom:${azure-sdk-bom.version} managedDep:com.azure:azure-core -->
<azure.core.http.client.vertx.version>1.0.0-beta.20</azure.core.http.client.vertx.version>
<assertj-core.version>3.26.3</assertj-core.version>
</properties>
Expand Down
6 changes: 3 additions & 3 deletions docs/modules/ROOT/pages/quarkus-azure-cosmos.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,13 @@ export QUARKUS_AZURE_COSMOS_ENDPOINT=$(az cosmosdb show \
echo "QUARKUS_AZURE_COSMOS_ENDPOINT is: ${QUARKUS_AZURE_COSMOS_ENDPOINT}"
----

Because Quarkus implements the [MicroProfile Config specification](https://microprofile.io/project/eclipse/microprofile-config), the value of the environment variable `QUARKUS_AZURE_COSMOS_ENDPOINT` is read as if the property `quarkus.azure.cosmos.endpoint` were set in the `application.properties` file.
Because Quarkus implements the https://microprofile.io/project/eclipse/microprofile-config[MicroProfile Config specification], the value of the environment variable `QUARKUS_AZURE_COSMOS_ENDPOINT` is read as if the property `quarkus.azure.cosmos.endpoint` were set in the `application.properties` file.

Although technically both approaches work, using environment variable is recommended and more secure as there's no risk of committing the connection string to source control.

=== Inject the Azure Cosmos DB Client

Now that your Azure environment is ready and you have configured the extension, you can `@Inject` the `com.azure.cosmos.CosmosClient` object in your imperative application or `@Inject` the `com.azure.cosmos.CosmosAsyncClient` object in your reactive application, so you can interact with Azure Cosmos DB. For complete API see [the Azure SDK for Java Reference Documentation](https://javadoc.io/doc/com.azure/azure-cosmos/latest/).
Now that your Azure environment is ready and you have configured the extension, you can `@Inject` the `com.azure.cosmos.CosmosClient` object in your imperative application or `@Inject` the `com.azure.cosmos.CosmosAsyncClient` object in your reactive application, so you can interact with Azure Cosmos DB. For complete API see https://javadoc.io/doc/com.azure/azure-cosmos/latest/[the Azure SDK for Java Reference Documentation].

==== Use the CosmosClient in an imperative application

Expand Down Expand Up @@ -163,7 +163,7 @@ image::quarkus-azure-cosmos-azure-portal2.png[alt=Azure Portal showing the conte
==== Use the CosmosAsyncClient in a reactive application

Similarly, the `createItem` method first asynchronously creates the item with request payload in the specified database and container of the Azure Cosmos DB account.
The `getItem` method asynchronously reads the item with the id from the specified database and container of the Azure Cosmos DB account. The sample makes heavy use of Project Reactor. For more information see [Reactor Reference Guide](https://projectreactor.io/docs/core/release/reference/).
The `getItem` method asynchronously reads the item with the id from the specified database and container of the Azure Cosmos DB account. The sample makes heavy use of Project Reactor. For more information see https://projectreactor.io/docs/core/release/reference/[Reactor Reference Guide].

[source,java]
----
Expand Down
5 changes: 0 additions & 5 deletions extensions/azure-cosmos/deployment/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,6 @@
</dependency>

<!-- Test dependencies -->
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-devservices-common</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5-internal</artifactId>
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public Uni<Response> createItem(
@Context UriInfo uriInfo) {

Mono<CosmosItemResponse<Item>> response = getContainer(database, container, true)
.flatMap(cosmosAsyncContainer -> cosmosAsyncContainer.upsertItem(body));
.upsertItem(body);
return Uni.createFrom().completionStage(response.toFuture())
.map(it -> Response.created(uriInfo.getAbsolutePathBuilder().path(body.getId()).build()).build());
}
Expand All @@ -46,7 +46,7 @@ public Uni<Response> getItem(
@PathParam("container") String container,
@PathParam("itemId") String itemId) {
Mono<CosmosItemResponse<Item>> item = getContainer(database, container, false)
.flatMap(cosmosAsyncContainer -> cosmosAsyncContainer.readItem(itemId, new PartitionKey(itemId), Item.class));
.readItem(itemId, new PartitionKey(itemId), Item.class);
return Uni.createFrom().completionStage(item.toFuture())
.map(it -> Response.ok().entity(it.getItem()).build());

Expand All @@ -59,8 +59,8 @@ public Uni<Response> deleteItem(
@PathParam("container") String container,
@PathParam("itemId") String itemId) {
Mono<CosmosItemResponse<Object>> response = getContainer(database, container, false)
.flatMap(cosmosAsyncContainer -> cosmosAsyncContainer.deleteItem(itemId, new PartitionKey(itemId),
new CosmosItemRequestOptions()));
.deleteItem(itemId, new PartitionKey(itemId),
new CosmosItemRequestOptions());
return Uni.createFrom().completionStage(response.toFuture())
.map(it -> Response.noContent().build());
}
Expand All @@ -72,21 +72,19 @@ public Multi<Item> getItems(
@PathParam("database") String database,
@PathParam("container") String container) {
Flux<Item> items = getContainer(database, container, false)
.map(cosmosAsyncContainer -> cosmosAsyncContainer
.queryItems("SELECT * FROM Item", new CosmosQueryRequestOptions(), Item.class)
.byPage(10)
.map(FeedResponse::getResults)
.flatMapIterable(it -> it))
.flatMapMany(flux -> flux);
.queryItems("SELECT * FROM Item", new CosmosQueryRequestOptions(), Item.class)
.byPage(10)
.map(FeedResponse::getResults)
.flatMapIterable(it -> it);

return Multi.createFrom().emitter(emitter -> {
items.subscribe(emitter::emit, emitter::fail, emitter::complete);
});
}

private Mono<CosmosAsyncContainer> getContainer(String database, String container, boolean createIfNotExists) {
private CosmosAsyncContainer getContainer(String database, String container, boolean createIfNotExists) {
if (!createIfNotExists) {
return Mono.just(cosmosAsyncClient.getDatabase(database).getContainer(container));
return cosmosAsyncClient.getDatabase(database).getContainer(container);
}

return cosmosAsyncClient.createDatabaseIfNotExists(database)
Expand All @@ -96,6 +94,7 @@ private Mono<CosmosAsyncContainer> getContainer(String database, String containe
.flatMap(databaseAsync -> databaseAsync.createContainerIfNotExists(container, Item.PARTITION_KEY))
.map(CosmosContainerResponse::getProperties)
.map(CosmosContainerProperties::getId)
.map(id -> cosmosAsyncClient.getDatabase(database).getContainer(container));
.map(id -> cosmosAsyncClient.getDatabase(database).getContainer(container))
.block();
}
}
Loading