1 package de.juplo.kafka.chat.backend.persistence.storage.mongodb;
3 import com.fasterxml.jackson.databind.ObjectMapper;
4 import de.juplo.kafka.chat.backend.ChatBackendProperties;
5 import de.juplo.kafka.chat.backend.persistence.StorageStrategy;
6 import de.juplo.kafka.chat.backend.persistence.inmemory.InMemoryChatRoomService;
7 import de.juplo.kafka.chat.backend.persistence.storage.files.FilesStorageStrategy;
8 import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
9 import org.springframework.context.annotation.Bean;
10 import org.springframework.context.annotation.Configuration;
11 import org.springframework.data.mongodb.repository.config.EnableReactiveMongoRepositories;
13 import java.nio.file.Paths;
14 import java.time.Clock;
17 @ConditionalOnProperty(
18 prefix = "chat.backend",
20 havingValue = "files")
22 @EnableReactiveMongoRepositories
23 public class MongoDbStorageConfiguration
26 public StorageStrategy storageStrategy(
27 ChatBackendProperties properties,
31 return new FilesStorageStrategy(
32 Paths.get(properties.getStorageDirectory()),
34 properties.getChatroomBufferSize(),
35 messageFlux -> new InMemoryChatRoomService(messageFlux),