2a3936cd51794e16bca5d2041a4c333eaa5fc80d
[demos/kafka/chat] /
1 package de.juplo.kafka.chat.backend.persistence.storage.files;
2
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.condition.ConditionalOnProperty;
8 import org.springframework.context.annotation.Bean;
9 import org.springframework.context.annotation.Configuration;
10
11 import java.nio.file.Paths;
12 import java.time.Clock;
13
14
15 @ConditionalOnProperty(
16     prefix = "chat.backend",
17     name = "storage",
18     havingValue = "files",
19     matchIfMissing = true)
20 @Configuration
21 public class FilesStorageAutoConfiguration
22 {
23   @Bean
24   public StorageStrategy storageStrategy(
25       ChatBackendProperties properties,
26       Clock clock,
27       ObjectMapper mapper)
28   {
29     return new FilesStorageStrategy(
30         Paths.get(properties.getStorageDirectory()),
31         clock,
32         properties.getChatroomBufferSize(),
33         messageFlux -> new InMemoryChatRoomService(messageFlux),
34         mapper);
35   }
36 }