From: Kai Moritz Date: Tue, 20 Feb 2024 10:28:22 +0000 (+0100) Subject: refactor: Refined stream-definition in `StorageStrategy#write` X-Git-Tag: rebase--2024-02-22~9 X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=f88050af507cd7164c56285f8fc2bfcd86a23273;p=demos%2Fkafka%2Fchat refactor: Refined stream-definition in `StorageStrategy#write` * Changed the stream-definition to a more natural order. * As a result, the stored `ChatRoomInfo`-instances do not have to be handed clumsily to the following stream. --- 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 94b2bb45..647ac523 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 @@ -17,19 +17,16 @@ public interface StorageStrategy default Mono write(ChatHomeService chatHomeService) { - return writeChatRoomInfo( - chatHomeService - .getChatRoomInfo() - .flatMap(chatRoomInfo -> writeChatRoomData( - chatRoomInfo.getId(), - chatHomeService - .getChatRoomData(chatRoomInfo.getId()) - .flatMapMany(chatRoomData -> chatRoomData.getMessages()) - ) - .then(Mono.just(chatRoomInfo)) - .doOnSuccess(emittedChatRoomInfo -> log.info("Stored {}", chatRoomInfo)) - .doOnError(throwable -> log.error("Could not store {}: {}", chatRoomInfo, throwable))) - ) + return writeChatRoomInfo(chatHomeService.getChatRoomInfo()) + .flatMap(chatRoomInfo -> writeChatRoomData( + chatRoomInfo.getId(), + chatHomeService + .getChatRoomData(chatRoomInfo.getId()) + .flatMapMany(chatRoomData -> chatRoomData.getMessages()) + ) + .then() + .doOnSuccess(empty -> log.info("Stored {}", chatRoomInfo)) + .doOnError(throwable -> log.error("Could not store {}: {}", chatRoomInfo, throwable))) .then() .doOnSuccess(empty -> log.info("Stored {}", chatHomeService)) .doOnError(throwable -> log.error("Could not store {}: {}", chatHomeService, throwable));