From 082bc7dfb6580c4817c8bf7cfd4abe2411860440 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 b1bead9b..2989d55f 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()); @@ -51,8 +50,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