feat: Introduced config switches to choose the used implementations
[demos/kafka/chat] / src / main / java / de / juplo / kafka / chat / backend / persistence / storage / files / FilesStorageConfiguration.java
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 FilesStorageConfiguration
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 }