WIP:mongodb REACTIVE
authorKai Moritz <kai@juplo.de>
Sat, 3 Feb 2024 23:24:07 +0000 (00:24 +0100)
committerKai Moritz <kai@juplo.de>
Tue, 20 Feb 2024 12:04:21 +0000 (13:04 +0100)
pom.xml
src/main/java/de/juplo/kafka/chat/backend/storage/mongodb/ChatRoomRepository.java
src/main/java/de/juplo/kafka/chat/backend/storage/mongodb/MessageRepository.java
src/main/java/de/juplo/kafka/chat/backend/storage/mongodb/MongoDbStorageStrategy.java

diff --git a/pom.xml b/pom.xml
index 04fe374..0737d96 100644 (file)
--- a/pom.xml
+++ b/pom.xml
@@ -44,7 +44,7 @@
     </dependency>
     <dependency>
       <groupId>org.springframework.boot</groupId>
-      <artifactId>spring-boot-starter-data-mongodb</artifactId>
+      <artifactId>spring-boot-starter-data-mongodb-reactive</artifactId>
     </dependency>
     <dependency>
       <groupId>org.apache.kafka</groupId>
index d9f6a0f..9262bf6 100644 (file)
@@ -1,8 +1,8 @@
 package de.juplo.kafka.chat.backend.storage.mongodb;
 
-import org.springframework.data.mongodb.repository.MongoRepository;
+import org.springframework.data.mongodb.repository.ReactiveMongoRepository;
 
 
-public interface ChatRoomRepository extends MongoRepository<ChatRoomTo, String>
+public interface ChatRoomRepository extends ReactiveMongoRepository<ChatRoomTo, String>
 {
 }
index 712f5a4..db8503c 100644 (file)
@@ -1,11 +1,10 @@
 package de.juplo.kafka.chat.backend.storage.mongodb;
 
-import org.springframework.data.mongodb.repository.MongoRepository;
+import org.springframework.data.mongodb.repository.ReactiveMongoRepository;
+import reactor.core.publisher.Flux;
 
-import java.util.List;
 
-
-public interface MessageRepository extends MongoRepository<MessageTo, String>
+public interface MessageRepository extends ReactiveMongoRepository<MessageTo, String>
 {
-  List<MessageTo> findByChatRoomIdOrderBySerialAsc(String chatRoomId);
+  Flux<MessageTo> findByChatRoomIdOrderBySerialAsc(String chatRoomId);
 }
index 1428119..95b1dd6 100644 (file)
@@ -32,8 +32,7 @@ public class MongoDbStorageStrategy implements StorageStrategy
   @Override
   public Flux<ChatRoomInfo> readChatRoomInfo()
   {
-    return Flux
-        .fromIterable(chatRoomRepository.findAll())
+    return chatRoomRepository.findAll()
         .map(chatRoomTo ->
         {
           UUID chatRoomId = UUID.fromString(chatRoomTo.getId());
@@ -53,8 +52,7 @@ public class MongoDbStorageStrategy implements StorageStrategy
   @Override
   public Flux<Message> readChatRoomData(UUID chatRoomId)
   {
-    return Flux
-        .fromIterable(messageRepository.findByChatRoomIdOrderBySerialAsc(chatRoomId.toString()))
+    return messageRepository.findByChatRoomIdOrderBySerialAsc(chatRoomId.toString())
         .map(messageTo -> messageTo.toMessage());
   }
 }