diff --git a/bulk-update-with-spring-data-mongodb-reactive/.run/Application.run.xml b/bulk-update-with-spring-data-mongodb-reactive/.run/Application.run.xml
index b4eb1a3..14ad679 100644
--- a/bulk-update-with-spring-data-mongodb-reactive/.run/Application.run.xml
+++ b/bulk-update-with-spring-data-mongodb-reactive/.run/Application.run.xml
@@ -6,6 +6,7 @@
+
diff --git a/bulk-update-with-spring-data-mongodb-reactive/docker-compose.yml b/bulk-update-with-spring-data-mongodb-reactive/docker-compose.yml
index a1ab405..d5edbd6 100644
--- a/bulk-update-with-spring-data-mongodb-reactive/docker-compose.yml
+++ b/bulk-update-with-spring-data-mongodb-reactive/docker-compose.yml
@@ -21,7 +21,9 @@ services:
networks:
- mongodb-network
environment:
- - ME_CONFIG_MONGODB_URL=mongodb://maoudia-mongodb:15015/?replicaSet=rs0
+ - ME_CONFIG_BASICAUTH_USERNAME=admin
+ - ME_CONFIG_BASICAUTH_PASSWORD=password
+ - ME_CONFIG_MONGODB_URL=mongodb://maoudia-mongodb:15015
ports:
- 1515:8081
volumes:
diff --git a/bulk-update-with-spring-data-mongodb-reactive/pom.xml b/bulk-update-with-spring-data-mongodb-reactive/pom.xml
index c6228aa..583af42 100644
--- a/bulk-update-with-spring-data-mongodb-reactive/pom.xml
+++ b/bulk-update-with-spring-data-mongodb-reactive/pom.xml
@@ -15,11 +15,12 @@
Bulk Update with Spring data MongoDB Reactive
21
- 4.1.76.Final
1.14.11
3.6.2
+ 4.1.76.Final
false
+ false
@@ -51,7 +52,6 @@
spring-boot-configuration-processor
true
-
io.projectreactor
reactor-tools
diff --git a/bulk-update-with-spring-data-mongodb-reactive/src/main/java/com/maoudia/tutorial/CollectionService.java b/bulk-update-with-spring-data-mongodb-reactive/src/main/java/com/maoudia/tutorial/CollectionService.java
index 450b82d..8e6e22c 100644
--- a/bulk-update-with-spring-data-mongodb-reactive/src/main/java/com/maoudia/tutorial/CollectionService.java
+++ b/bulk-update-with-spring-data-mongodb-reactive/src/main/java/com/maoudia/tutorial/CollectionService.java
@@ -1,18 +1,19 @@
package com.maoudia.tutorial;
-import com.mongodb.TransactionOptions;
import com.mongodb.bulk.BulkWriteResult;
import com.mongodb.client.model.BulkWriteOptions;
import com.mongodb.client.model.Filters;
import com.mongodb.client.model.ReplaceOneModel;
import com.mongodb.client.model.ReplaceOptions;
+import io.micrometer.core.instrument.MeterRegistry;
+import io.micrometer.observation.ObservationRegistry;
import org.bson.Document;
import org.reactivestreams.Publisher;
import org.springframework.data.mongodb.core.ReactiveMongoTemplate;
-import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import org.springframework.transaction.reactive.TransactionalOperator;
import org.springframework.web.reactive.function.client.WebClient;
+import reactor.core.observability.micrometer.Micrometer;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
@@ -36,21 +37,26 @@ private static ReplaceOneModel toReplaceOneModel(Document document) {
private final ReactiveMongoTemplate template;
private final WebClient client;
private final TransactionalOperator transactionalOperator;
+ private final MeterRegistry meterRegistry;
public CollectionService(AppProperties properties,
ReactiveMongoTemplate template,
WebClient client,
- TransactionalOperator transactionalOperator) {
+ TransactionalOperator transactionalOperator, ObservationRegistry observationRegistry, MeterRegistry meterRegistry) {
this.properties = properties;
this.template = template;
this.client = client;
this.transactionalOperator = transactionalOperator;
+ this.meterRegistry = meterRegistry;
}
public Flux enrichAll(String collectionName,
String enrichingKey,
URI enrichingUri) {
return template.findAll(Document.class, collectionName)
+ .name("app.documents.flux")
+ .tag("source", "mongodb")
+ .tap(Micrometer.metrics(meterRegistry))
.onBackpressureBuffer(properties.bufferMaxSize())
.flatMap(document -> enrich(document, enrichingKey, enrichingUri))
.map(CollectionService::toReplaceOneModel)
@@ -73,16 +79,24 @@ private Mono getEnrichingDocument(URI enrichingUri) {
return client.get()
.uri(enrichingUri)
.retrieve()
- .bodyToMono(Document.class);
+ .bodyToMono(Document.class)
+ .name("app.enriching.call")
+ .tag("source", "http")
+ .doOnNext(unused -> meterRegistry.getMeters())
+ .tap(Micrometer.metrics(meterRegistry));
}
private Publisher bulkWrite(Flux> updateOneModelFlux,
String collectionName) {
return updateOneModelFlux
+ .name("app.documents.bulk")
+ .tap(Micrometer.metrics(meterRegistry))
.collectList()
.flatMapMany(updateOneModels -> template.getCollection(collectionName)
.flatMapMany(collection -> collection.bulkWrite(updateOneModels, BULK_WRITE_OPTIONS)))
- .as(transactionalOperator::transactional);
+ .as(transactionalOperator::transactional)
+ .name("app.transactions")
+ .tap(Micrometer.metrics(meterRegistry));
}
}
diff --git a/bulk-update-with-spring-data-mongodb-reactive/src/main/resources/application.yml b/bulk-update-with-spring-data-mongodb-reactive/src/main/resources/application.yml
index f6eeb29..aab82c6 100644
--- a/bulk-update-with-spring-data-mongodb-reactive/src/main/resources/application.yml
+++ b/bulk-update-with-spring-data-mongodb-reactive/src/main/resources/application.yml
@@ -8,16 +8,16 @@ spring:
application:
name: bulk-update-with-spring-data-mongodb-reactive
main:
- web-application-type: none
+ web-application-type: NONE
data:
mongodb:
database: test
- uri: mongodb://localhost:15015/?replicaSet=rs0&retryWrites=false
+ uri: mongodb://localhost:15015
---
spring.config.activate.on-profile: dev
logging:
level:
- org.mongodb.driver: debug
+ org.mongodb.driver: DEBUG
---
spring.config.activate.on-profile: test
app: