From: Kai Moritz Date: Wed, 11 Jan 2023 17:38:39 +0000 (+0100) Subject: feat: configuration for service & storage lives in the according packages X-Git-Tag: wip~42 X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=1c77d6f54595a9d25a7a8329cd6e10c785c51f50;p=demos%2Fkafka%2Fchat feat: configuration for service & storage lives in the according packages --- diff --git a/src/main/java/de/juplo/kafka/chat/backend/ChatBackendConfiguration.java b/src/main/java/de/juplo/kafka/chat/backend/ChatBackendConfiguration.java index 0cca42d3..ac77748e 100644 --- a/src/main/java/de/juplo/kafka/chat/backend/ChatBackendConfiguration.java +++ b/src/main/java/de/juplo/kafka/chat/backend/ChatBackendConfiguration.java @@ -1,18 +1,12 @@ package de.juplo.kafka.chat.backend; import de.juplo.kafka.chat.backend.domain.ChatHome; -import com.fasterxml.jackson.databind.ObjectMapper; import de.juplo.kafka.chat.backend.domain.ChatHomeService; -import de.juplo.kafka.chat.backend.persistence.inmemory.InMemoryChatHomeService; -import de.juplo.kafka.chat.backend.persistence.storage.files.FilesStorageStrategy; -import de.juplo.kafka.chat.backend.persistence.StorageStrategy; -import de.juplo.kafka.chat.backend.persistence.inmemory.InMemoryChatRoomService; 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.nio.file.Paths; import java.time.Clock; @@ -27,32 +21,6 @@ public class ChatBackendConfiguration return new ChatHome(chatHomeService); } - @Bean - InMemoryChatHomeService chatHomeService( - StorageStrategy storageStrategy, - Clock clock, - ChatBackendProperties properties) - { - return new InMemoryChatHomeService( - storageStrategy.read(), - clock, - properties.getChatroomBufferSize()); - } - - @Bean - public StorageStrategy storageStrategy( - ChatBackendProperties properties, - Clock clock, - ObjectMapper mapper) - { - return new FilesStorageStrategy( - Paths.get(properties.getStorageDirectory()), - clock, - properties.getChatroomBufferSize(), - messageFlux -> new InMemoryChatRoomService(messageFlux), - mapper); - } - @Bean public Clock clock() { diff --git a/src/main/java/de/juplo/kafka/chat/backend/persistence/inmemory/InMemoryServicesConfiguration.java b/src/main/java/de/juplo/kafka/chat/backend/persistence/inmemory/InMemoryServicesConfiguration.java new file mode 100644 index 00000000..20a1b5f6 --- /dev/null +++ b/src/main/java/de/juplo/kafka/chat/backend/persistence/inmemory/InMemoryServicesConfiguration.java @@ -0,0 +1,25 @@ +package de.juplo.kafka.chat.backend.persistence.inmemory; + +import de.juplo.kafka.chat.backend.ChatBackendProperties; +import de.juplo.kafka.chat.backend.persistence.StorageStrategy; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import java.time.Clock; + + +@Configuration +public class InMemoryServicesConfiguration +{ + @Bean + InMemoryChatHomeService chatHomeService( + StorageStrategy storageStrategy, + Clock clock, + ChatBackendProperties properties) + { + return new InMemoryChatHomeService( + storageStrategy.read(), + clock, + properties.getChatroomBufferSize()); + } +} diff --git a/src/main/java/de/juplo/kafka/chat/backend/persistence/storage/files/FilesStorageConfiguration.java b/src/main/java/de/juplo/kafka/chat/backend/persistence/storage/files/FilesStorageConfiguration.java new file mode 100644 index 00000000..32bedb8f --- /dev/null +++ b/src/main/java/de/juplo/kafka/chat/backend/persistence/storage/files/FilesStorageConfiguration.java @@ -0,0 +1,30 @@ +package de.juplo.kafka.chat.backend.persistence.storage.files; + +import com.fasterxml.jackson.databind.ObjectMapper; +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.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import java.nio.file.Paths; +import java.time.Clock; + + +@Configuration +public class FilesStorageConfiguration +{ + @Bean + public StorageStrategy storageStrategy( + ChatBackendProperties properties, + Clock clock, + ObjectMapper mapper) + { + return new FilesStorageStrategy( + Paths.get(properties.getStorageDirectory()), + clock, + properties.getChatroomBufferSize(), + messageFlux -> new InMemoryChatRoomService(messageFlux), + mapper); + } +}