From: Kai Moritz Date: Tue, 20 Feb 2024 10:14:43 +0000 (+0100) Subject: refactor: Refined return-type of `StorageStrategy#write` X-Git-Tag: rebase--2024-02-22~10 X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=15eafdcf744b4d164876510084e4e3c71c286433;p=demos%2Fkafka%2Fchat refactor: Refined return-type of `StorageStrategy#write` --- 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 487a37fe..94b2bb45 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 @@ -15,7 +15,7 @@ public interface StorageStrategy { Logger log = LoggerFactory.getLogger(StorageStrategy.class.getCanonicalName()); - default Flux write(ChatHomeService chatHomeService) + default Mono write(ChatHomeService chatHomeService) { return writeChatRoomInfo( chatHomeService @@ -30,7 +30,8 @@ public interface StorageStrategy .doOnSuccess(emittedChatRoomInfo -> log.info("Stored {}", chatRoomInfo)) .doOnError(throwable -> log.error("Could not store {}: {}", chatRoomInfo, throwable))) ) - .doOnComplete(() -> log.info("Stored {}", chatHomeService)) + .then() + .doOnSuccess(empty -> log.info("Stored {}", chatHomeService)) .doOnError(throwable -> log.error("Could not store {}: {}", chatHomeService, throwable)); } diff --git a/src/main/java/de/juplo/kafka/chat/backend/storage/nostorage/NoStorageStorageStrategy.java b/src/main/java/de/juplo/kafka/chat/backend/storage/nostorage/NoStorageStorageStrategy.java index 59027424..46189b6c 100644 --- a/src/main/java/de/juplo/kafka/chat/backend/storage/nostorage/NoStorageStorageStrategy.java +++ b/src/main/java/de/juplo/kafka/chat/backend/storage/nostorage/NoStorageStorageStrategy.java @@ -6,6 +6,7 @@ import de.juplo.kafka.chat.backend.domain.Message; import de.juplo.kafka.chat.backend.implementation.StorageStrategy; import lombok.extern.slf4j.Slf4j; import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; import java.util.UUID; @@ -13,11 +14,11 @@ import java.util.UUID; @Slf4j public class NoStorageStorageStrategy implements StorageStrategy { - public Flux write(ChatHomeService chatHomeService) + public Mono write(ChatHomeService chatHomeService) { - return Flux - .empty() - .doOnComplete(() -> log.info("Storage is disabled: Not storing {}", chatHomeService)); + return Mono + .empty() + .doOnSuccess(empty -> log.info("Storage is disabled: Not storing {}", chatHomeService)); }