2b33eed72657f579cc5e0138ab83dbb8e333c8e1
[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.domain.ShardingStrategy;
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.time.Clock;
12
13
14 @ConditionalOnProperty(
15     prefix = "chat.backend.inmemory",
16     name = "storage-strategy",
17     havingValue = "mongodb")
18 @Configuration
19 public class MongoDbStorageConfiguration
20 {
21   @Bean
22   public StorageStrategy storageStrategy(
23       ChatRoomRepository chatRoomRepository,
24       ChatBackendProperties properties,
25       Clock clock,
26       ShardingStrategy shardingStrategy)
27   {
28     return new MongoDbStorageStrategy(
29         chatRoomRepository,
30         clock,
31         properties.getChatroomBufferSize(),
32         shardingStrategy,
33         messageFlux -> new InMemoryChatRoomService(messageFlux));
34   }
35 }