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.ChatHomeService;
6 import de.juplo.kafka.chat.backend.persistence.inmemory.InMemoryChatHomeService;
7 import de.juplo.kafka.chat.backend.persistence.filestorage.FileStorageStrategy;
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(ChatHomeService chatHomeService)
24 return new ChatHome(chatHomeService);
28 InMemoryChatHomeService chatHomeService(
29 StorageStrategy storageStrategy,
31 ChatBackendProperties properties)
33 return new InMemoryChatHomeService(
34 storageStrategy.readChatrooms(),
36 properties.getChatroomBufferSize());
40 public StorageStrategy storageStrategy(
41 ChatBackendProperties properties,
45 return new FileStorageStrategy(
46 Paths.get(properties.getStorageDirectory()),
48 properties.getChatroomBufferSize(),
55 return Clock.systemDefaultZone();