c2b014e06b9f5706af0a9873cbc98700c3a978ed
[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.inmemory.ShardingStrategy;
5 import de.juplo.kafka.chat.backend.persistence.StorageStrategy;
6 import de.juplo.kafka.chat.backend.persistence.inmemory.InMemoryChatRoomService;
7 import de.juplo.kafka.chat.backend.persistence.storage.files.ChatRoomServiceFactory;
8 import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
9 import org.springframework.context.annotation.Bean;
10 import org.springframework.context.annotation.Configuration;
11
12 import java.time.Clock;
13
14
15 @ConditionalOnProperty(
16     prefix = "chat.backend.inmemory",
17     name = "storage-strategy",
18     havingValue = "mongodb")
19 @Configuration
20 public class MongoDbStorageConfiguration
21 {
22   @Bean
23   public StorageStrategy storageStrategy(
24       ChatRoomRepository chatRoomRepository,
25       MessageRepository messageRepository,
26       ChatBackendProperties properties,
27       Clock clock,
28       ShardingStrategy shardingStrategy,
29       ChatRoomServiceFactory chatRoomServiceFactory)
30   {
31     return new MongoDbStorageStrategy(
32         chatRoomRepository,
33         messageRepository,
34         clock,
35         properties.getChatroomBufferSize(),
36         shardingStrategy,
37         chatRoomServiceFactory);
38   }
39 }