1 package de.juplo.kafka.chat.backend;
3 import de.juplo.kafka.chat.backend.domain.ChatHome;
4 import com.fasterxml.jackson.databind.ObjectMapper;
5 import de.juplo.kafka.chat.backend.domain.ChatroomFactory;
6 import de.juplo.kafka.chat.backend.persistence.InMemoryChatroomFactory;
7 import de.juplo.kafka.chat.backend.persistence.LocalJsonFilesStorageStrategy;
8 import de.juplo.kafka.chat.backend.persistence.StorageStrategy;
9 import org.springframework.boot.context.properties.EnableConfigurationProperties;
10 import org.springframework.context.annotation.Bean;
11 import org.springframework.context.annotation.Configuration;
13 import java.nio.file.Paths;
14 import java.time.Clock;
18 @EnableConfigurationProperties(ChatBackendProperties.class)
19 public class ChatBackendConfiguration
22 public ChatHome chatHome(
23 ChatroomFactory chatroomFactory,
24 StorageStrategy storageStrategy)
26 return new ChatHome(chatroomFactory, storageStrategy.readChatrooms());
30 public StorageStrategy storageStrategy(
31 ChatBackendProperties properties,
33 InMemoryChatroomFactory chatroomFactory)
35 return new LocalJsonFilesStorageStrategy(
36 Paths.get(properties.getDatadir()),
42 InMemoryChatroomFactory chatroomFactory(ChatBackendProperties properties)
44 return new InMemoryChatroomFactory(properties.getChatroomBufferSize());
50 return Clock.systemDefaultZone();