From: Kai Moritz Date: Sat, 3 Feb 2024 23:37:23 +0000 (+0100) Subject: refactor: Extracted subscription into a separate method-call X-Git-Tag: rebase--2024-02-22~15 X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=c786c4a079da27f54e75d22e2d2c2a1693aba078;p=demos%2Fkafka%2Fchat refactor: Extracted subscription into a separate method-call * This is in preparation to a planed refinement. * The refinment will move the `subscribe()`-call out of the implementation of the `StorageStrategy`. --- diff --git a/src/main/java/de/juplo/kafka/chat/backend/storage/files/FilesStorageStrategy.java b/src/main/java/de/juplo/kafka/chat/backend/storage/files/FilesStorageStrategy.java index cb7dd31e..7e04a964 100644 --- a/src/main/java/de/juplo/kafka/chat/backend/storage/files/FilesStorageStrategy.java +++ b/src/main/java/de/juplo/kafka/chat/backend/storage/files/FilesStorageStrategy.java @@ -74,18 +74,20 @@ public class FilesStorageStrategy implements StorageStrategy throw new RuntimeException(e); } }) - .subscribe(chatRoomInfo -> + .map(chatRoomInfo -> { try { ChatRoomInfoTo chatRoomInfoTo = ChatRoomInfoTo.from(chatRoomInfo); generator.writeObject(chatRoomInfoTo); + return chatRoomInfo; } catch (IOException e) { throw new RuntimeException(e); } - }); + }) + .subscribe(); } catch (IOException e) { @@ -160,18 +162,20 @@ public class FilesStorageStrategy implements StorageStrategy throw new RuntimeException(e); } }) - .subscribe(message -> + .map(message -> { try { MessageTo messageTo = MessageTo.from(message); generator.writeObject(messageTo); + return message; } catch (IOException e) { throw new RuntimeException(e); } - }); + }) + .subscribe(); } catch (IOException e) { diff --git a/src/main/java/de/juplo/kafka/chat/backend/storage/mongodb/MongoDbStorageStrategy.java b/src/main/java/de/juplo/kafka/chat/backend/storage/mongodb/MongoDbStorageStrategy.java index b1bead9b..780d64be 100644 --- a/src/main/java/de/juplo/kafka/chat/backend/storage/mongodb/MongoDbStorageStrategy.java +++ b/src/main/java/de/juplo/kafka/chat/backend/storage/mongodb/MongoDbStorageStrategy.java @@ -25,7 +25,8 @@ public class MongoDbStorageStrategy implements StorageStrategy { chatRoomInfoFlux .map(ChatRoomTo::from) - .subscribe(chatroomTo -> chatRoomRepository.save(chatroomTo)); + .map(chatroomTo -> chatRoomRepository.save(chatroomTo)) + .subscribe(); } @Override @@ -45,7 +46,8 @@ public class MongoDbStorageStrategy implements StorageStrategy { messageFlux .map(message -> MessageTo.from(chatRoomId, message)) - .subscribe(messageTo -> messageRepository.save(messageTo)); + .map(messageTo -> messageRepository.save(messageTo)) + .subscribe(); } @Override