1 package de.juplo.kafka.chat.backend.persistence.storage.files;
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 org.springframework.boot.autoconfigure.EnableAutoConfiguration;
8 import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
9 import org.springframework.boot.autoconfigure.data.mongo.MongoRepositoriesAutoConfiguration;
10 import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration;
11 import org.springframework.context.annotation.Bean;
12 import org.springframework.context.annotation.Configuration;
14 import java.nio.file.Paths;
15 import java.time.Clock;
18 @ConditionalOnProperty(
19 prefix = "chat.backend.inmemory",
20 name = "storage-strategy",
21 havingValue = "files",
22 matchIfMissing = true)
24 @EnableAutoConfiguration(
26 MongoRepositoriesAutoConfiguration.class,
27 MongoAutoConfiguration.class })
28 public class FilesStorageConfiguration
31 public StorageStrategy storageStrategy(
32 ChatBackendProperties properties,
36 return new FilesStorageStrategy(
37 Paths.get(properties.getInmemory().getStorageDirectory()),
39 properties.getChatroomBufferSize(),
41 messageFlux -> new InMemoryChatRoomService(messageFlux),