@PreDestroy
public void onExit()
{
- storageStrategy.writeChatRoomInfo(
- chatHome
- .getChatRoomInfo()
- .doOnNext(chatRoomInfo ->
- storageStrategy.writeChatRoomData(
- chatRoomInfo.getId(),
- chatHome
- .getChatRoomData(chatRoomInfo.getId())
- .flatMapMany(chatRoomData -> chatRoomData.getMessages()))));
+ storageStrategy.write(chatHome);
}
public static void main(String[] args)
@PostMapping("/store")
public void store()
{
- storageStrategy.writeChatRoomInfo(
- chatHome
- .getChatRoomInfo()
- .doOnNext(chatRoomInfo ->
- storageStrategy.writeChatRoomData(
- chatRoomInfo.getId(),
- chatHome
- .getChatRoomData(chatRoomInfo.getId())
- .flatMapMany(chatRoomData -> chatRoomData.getMessages()))));
+ storageStrategy.write(chatHome);
}
}
package de.juplo.kafka.chat.backend.persistence;
+import de.juplo.kafka.chat.backend.domain.ChatHome;
import de.juplo.kafka.chat.backend.domain.ChatRoomInfo;
import de.juplo.kafka.chat.backend.domain.Message;
import reactor.core.publisher.Flux;
public interface StorageStrategy
{
+ default void write(ChatHome chatHome)
+ {
+ writeChatRoomInfo(
+ chatHome
+ .getChatRoomInfo()
+ .doOnNext(chatRoomInfo ->
+ writeChatRoomData(
+ chatRoomInfo.getId(),
+ chatHome
+ .getChatRoomData(chatRoomInfo.getId())
+ .flatMapMany(chatRoomData -> chatRoomData.getMessages()))));
+ }
+
void writeChatRoomInfo(Flux<ChatRoomInfo> chatRoomInfoFlux);
Flux<ChatRoomInfo> readChatRoomInfo();
void writeChatRoomData(UUID chatRoomId, Flux<Message> messageFlux);