feat: Introduced config switches to choose the used implementations
[demos/kafka/chat] / src / main / java / de / juplo / kafka / chat / backend / persistence / inmemory / InMemoryServicesConfiguration.java
1 package de.juplo.kafka.chat.backend.persistence.inmemory;
2
3 import de.juplo.kafka.chat.backend.ChatBackendProperties;
4 import de.juplo.kafka.chat.backend.persistence.StorageStrategy;
5 import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
6 import org.springframework.context.annotation.Bean;
7 import org.springframework.context.annotation.Configuration;
8
9 import java.time.Clock;
10
11
12 @ConditionalOnProperty(
13     prefix = "chat.backend",
14     name = "services",
15     havingValue = "in-memory",
16     matchIfMissing = true)
17 @Configuration
18 public class InMemoryServicesConfiguration
19 {
20   @Bean
21   InMemoryChatHomeService chatHomeService(
22       StorageStrategy storageStrategy,
23       Clock clock,
24       ChatBackendProperties properties)
25   {
26     return new InMemoryChatHomeService(
27         storageStrategy.read(),
28         clock,
29         properties.getChatroomBufferSize());
30   }
31 }