From 947f13a354ff1fd388bdfca1be764fda5bd8db93 Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Tue, 20 Feb 2024 08:50:56 +0100 Subject: [PATCH] refactor: One stream -> using `flatMap` instead of an inner `subscribe` --- .../chat/backend/implementation/StorageStrategy.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main/java/de/juplo/kafka/chat/backend/implementation/StorageStrategy.java b/src/main/java/de/juplo/kafka/chat/backend/implementation/StorageStrategy.java index 6b290fdf..f9ce2b12 100644 --- a/src/main/java/de/juplo/kafka/chat/backend/implementation/StorageStrategy.java +++ b/src/main/java/de/juplo/kafka/chat/backend/implementation/StorageStrategy.java @@ -6,6 +6,7 @@ import de.juplo.kafka.chat.backend.domain.Message; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; import java.util.UUID; @@ -19,16 +20,16 @@ public interface StorageStrategy return writeChatRoomInfo( chatHomeService .getChatRoomInfo() - .doOnNext(chatRoomInfo -> + .flatMap(chatRoomInfo -> writeChatRoomData( chatRoomInfo.getId(), chatHomeService .getChatRoomData(chatRoomInfo.getId()) .flatMapMany(chatRoomData -> chatRoomData.getMessages()) ) - .doOnComplete(() -> log.info("Stored {}", chatRoomInfo)) - .doOnError(throwable -> log.error("Could not store {}: {}", chatRoomInfo, throwable)) - .subscribe())) + .then(Mono.just(chatRoomInfo)) + .doOnSuccess(empty -> log.info("Stored {}", chatRoomInfo)) + .doOnError(throwable -> log.error("Could not store {}: {}", chatRoomInfo, throwable)))) .doOnComplete(() -> log.info("Stored {}", chatHomeService)) .doOnError(throwable -> log.error("Could not store {}: {}", chatHomeService, throwable)); } -- 2.20.1