From 601184d7a95bf6310462d6b2e1e8f9c501b3bc9e Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Sun, 4 Feb 2024 00:24:07 +0100 Subject: [PATCH] WIP:mongodb REACTIVE --- pom.xml | 2 +- .../chat/backend/storage/mongodb/ChatRoomRepository.java | 4 ++-- .../chat/backend/storage/mongodb/MessageRepository.java | 9 ++++----- .../backend/storage/mongodb/MongoDbStorageStrategy.java | 6 ++---- 4 files changed, 9 insertions(+), 12 deletions(-) diff --git a/pom.xml b/pom.xml index 04fe3747..0737d962 100644 --- a/pom.xml +++ b/pom.xml @@ -44,7 +44,7 @@ org.springframework.boot - spring-boot-starter-data-mongodb + spring-boot-starter-data-mongodb-reactive org.apache.kafka diff --git a/src/main/java/de/juplo/kafka/chat/backend/storage/mongodb/ChatRoomRepository.java b/src/main/java/de/juplo/kafka/chat/backend/storage/mongodb/ChatRoomRepository.java index d9f6a0f5..9262bf66 100644 --- a/src/main/java/de/juplo/kafka/chat/backend/storage/mongodb/ChatRoomRepository.java +++ b/src/main/java/de/juplo/kafka/chat/backend/storage/mongodb/ChatRoomRepository.java @@ -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 +public interface ChatRoomRepository extends ReactiveMongoRepository { } diff --git a/src/main/java/de/juplo/kafka/chat/backend/storage/mongodb/MessageRepository.java b/src/main/java/de/juplo/kafka/chat/backend/storage/mongodb/MessageRepository.java index 712f5a4a..db8503c3 100644 --- a/src/main/java/de/juplo/kafka/chat/backend/storage/mongodb/MessageRepository.java +++ b/src/main/java/de/juplo/kafka/chat/backend/storage/mongodb/MessageRepository.java @@ -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 +public interface MessageRepository extends ReactiveMongoRepository { - List findByChatRoomIdOrderBySerialAsc(String chatRoomId); + Flux findByChatRoomIdOrderBySerialAsc(String chatRoomId); } 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 972122e0..9a87d448 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 @@ -31,8 +31,7 @@ public class MongoDbStorageStrategy implements StorageStrategy @Override public Flux readChatRoomInfo() { - return Flux - .fromIterable(chatRoomRepository.findAll()) + return chatRoomRepository.findAll() .map(chatRoomTo -> { UUID chatRoomId = UUID.fromString(chatRoomTo.getId()); @@ -57,8 +56,7 @@ public class MongoDbStorageStrategy implements StorageStrategy @Override public Flux readChatRoomData(UUID chatRoomId) { - return Flux - .fromIterable(messageRepository.findByChatRoomIdOrderBySerialAsc(chatRoomId.toString())) + return messageRepository.findByChatRoomIdOrderBySerialAsc(chatRoomId.toString()) .map(messageTo -> messageTo.toMessage()); } } -- 2.20.1