120fab34230ef726751958450293e92e8bfa0657
[demos/kafka/chat] /
1 package de.juplo.kafka.chat.backend.persistence.storage.mongodb;
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 de.juplo.kafka.chat.backend.persistence.storage.files.FilesStorageStrategy;
8 import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
9 import org.springframework.context.annotation.Bean;
10 import org.springframework.context.annotation.Configuration;
11 import org.springframework.data.mongodb.repository.config.EnableReactiveMongoRepositories;
12
13 import java.nio.file.Paths;
14 import java.time.Clock;
15
16
17 @ConditionalOnProperty(
18     prefix = "chat.backend",
19     name = "mongodb",
20     havingValue = "files")
21 @Configuration
22 @EnableReactiveMongoRepositories
23 public class MongoDbStorageConfiguration
24 {
25   @Bean
26   public StorageStrategy storageStrategy(
27       ChatBackendProperties properties,
28       Clock clock,
29       ObjectMapper mapper)
30   {
31     return new FilesStorageStrategy(
32         Paths.get(properties.getStorageDirectory()),
33         clock,
34         properties.getChatroomBufferSize(),
35         messageFlux -> new InMemoryChatRoomService(messageFlux),
36         mapper);
37   }
38 }