From: Kai Moritz Date: Sat, 3 Feb 2024 23:37:23 +0000 (+0100) Subject: WIP:mongodb map vs subscribe X-Git-Tag: rebase--2024-02-20--09-03~4 X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=de820ef239e2783b0542f413c5cb2ada93dc9361;p=demos%2Fkafka%2Fchat WIP:mongodb map vs subscribe --- 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