From b10219b9c62f92a1175ed4ee196eab1ee4b64a54 Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Sun, 4 Feb 2024 00:37:23 +0100 Subject: [PATCH] WIP:mongodb map vs subscribe --- .../backend/storage/files/FilesStorageStrategy.java | 12 ++++++++---- .../storage/mongodb/MongoDbStorageStrategy.java | 6 ++++-- 2 files changed, 12 insertions(+), 6 deletions(-) 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 -- 2.20.1