- Switched the existing `@Configuration`-classes into an auto-configuration.
- Added a `@ConditionalOnProperty`, that loades the default-configuration.
- Added an Auto-Configuration for the `MongoDbStorageStrategy`, which is
inactive by default and can be switched on by the property
`chat.backend.storage` to `mongodb`.
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
-import org.springframework.data.mongodb.repository.config.EnableReactiveMongoRepositories;
import java.time.Clock;
@Configuration
@EnableConfigurationProperties(ChatBackendProperties.class)
-@EnableReactiveMongoRepositories
public class ChatBackendConfiguration
{
@Bean
import de.juplo.kafka.chat.backend.ChatBackendProperties;
import de.juplo.kafka.chat.backend.persistence.StorageStrategy;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.time.Clock;
+@ConditionalOnProperty(
+ prefix = "chat.backend",
+ name = "services",
+ havingValue = "in-memory",
+ matchIfMissing = true)
@Configuration
public class InMemoryServicesConfiguration
{
import de.juplo.kafka.chat.backend.ChatBackendProperties;
import de.juplo.kafka.chat.backend.persistence.StorageStrategy;
import de.juplo.kafka.chat.backend.persistence.inmemory.InMemoryChatRoomService;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.time.Clock;
+@ConditionalOnProperty(
+ prefix = "chat.backend",
+ name = "storage",
+ havingValue = "files",
+ matchIfMissing = true)
@Configuration
public class FilesStorageConfiguration
{
--- /dev/null
+package de.juplo.kafka.chat.backend.persistence.storage.mongodb;
+
+import de.juplo.kafka.chat.backend.ChatBackendProperties;
+import de.juplo.kafka.chat.backend.persistence.StorageStrategy;
+import de.juplo.kafka.chat.backend.persistence.inmemory.InMemoryChatRoomService;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+import java.time.Clock;
+
+
+@ConditionalOnProperty(
+ prefix = "chat.backend",
+ name = "storage",
+ havingValue = "mongodb")
+@Configuration
+public class MongoDbStorageConfiguration
+{
+ @Bean
+ public StorageStrategy storageStrategy(
+ ChatRoomRepository chatRoomRepository,
+ ChatBackendProperties properties,
+ Clock clock)
+ {
+ return new MongoDbStorageStrategy(
+ chatRoomRepository,
+ clock,
+ properties.getChatroomBufferSize(),
+ messageFlux -> new InMemoryChatRoomService(messageFlux));
+ }
+}