1 package de.juplo.kafka.chat.backend.implementation;
3 import de.juplo.kafka.chat.backend.domain.ChatHomeService;
4 import de.juplo.kafka.chat.backend.domain.ChatRoomInfo;
5 import de.juplo.kafka.chat.backend.domain.Message;
6 import org.slf4j.Logger;
7 import org.slf4j.LoggerFactory;
8 import reactor.core.publisher.Flux;
9 import reactor.core.publisher.Mono;
11 import java.util.UUID;
14 public interface StorageStrategy
16 Logger log = LoggerFactory.getLogger(StorageStrategy.class.getCanonicalName());
18 default Flux<ChatRoomInfo> write(ChatHomeService chatHomeService)
20 return writeChatRoomInfo(
23 .flatMap(chatRoomInfo ->
27 .getChatRoomData(chatRoomInfo.getId())
28 .flatMapMany(chatRoomData -> chatRoomData.getMessages())
30 .then(Mono.just(chatRoomInfo))
31 .doOnSuccess(empty -> log.info("Stored {}", chatRoomInfo))
32 .doOnError(throwable -> log.error("Could not store {}: {}", chatRoomInfo, throwable))))
33 .doOnComplete(() -> log.info("Stored {}", chatHomeService))
34 .doOnError(throwable -> log.error("Could not store {}: {}", chatHomeService, throwable));
37 Flux<ChatRoomInfo> writeChatRoomInfo(Flux<ChatRoomInfo> chatRoomInfoFlux);
38 Flux<ChatRoomInfo> readChatRoomInfo();
39 Flux<Message> writeChatRoomData(UUID chatRoomId, Flux<Message> messageFlux);
40 Flux<Message> readChatRoomData(UUID chatRoomId);