22d7c26ba638aa56e083f9bd636e291d86b35367
[demos/kafka/chat] /
1 package de.juplo.kafka.chat.backend.persistence.storage.mongodb;
2
3 import de.juplo.kafka.chat.backend.ChatBackendProperties;
4 import de.juplo.kafka.chat.backend.persistence.StorageStrategy;
5 import de.juplo.kafka.chat.backend.persistence.inmemory.InMemoryChatRoomService;
6 import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
7 import org.springframework.context.annotation.Bean;
8 import org.springframework.context.annotation.Configuration;
9
10 import java.time.Clock;
11
12
13 @ConditionalOnProperty(
14     prefix = "chat.backend.inmemory",
15     name = "storage-strategy",
16     havingValue = "mongodb")
17 @Configuration
18 public class MongoDbStorageConfiguration
19 {
20   @Bean
21   public StorageStrategy storageStrategy(
22       ChatRoomRepository chatRoomRepository,
23       ChatBackendProperties properties,
24       Clock clock)
25   {
26     return new MongoDbStorageStrategy(
27         chatRoomRepository,
28         clock,
29         properties.getChatroomBufferSize(),
30         messageFlux -> new InMemoryChatRoomService(messageFlux));
31   }
32 }