private ShardingStrategyType shardingStrategy = ShardingStrategyType.none;
private int numShards = 1;
private int[] ownedShards = new int[] { 0 };
- private StorageStrategyType storageStrategy = StorageStrategyType.files;
+ private StorageStrategyType storageStrategy = StorageStrategyType.none;
private String storageDirectory = Paths.get(System.getProperty("java.io.tmpdir"),"chat", "backend").toString();
}
public enum ServiceType { inmemory }
- public enum StorageStrategyType { files, mongodb }
+ public enum StorageStrategyType { none, files, mongodb }
public enum ShardingStrategyType { none, kafkalike }
}
import org.springframework.context.annotation.Configuration;
import java.time.Clock;
+import java.util.stream.IntStream;
@ConditionalOnProperty(
havingValue = "kafkalike")
ChatHome kafkalikeShardingChatHome(
ChatBackendProperties properties,
- InMemoryChatHomeService chatHomeService,
- StorageStrategy storageStrategy)
+ InMemoryChatHomeService chatHomeService)
{
int numShards = properties.getInmemory().getNumShards();
SimpleChatHome[] chatHomes = new SimpleChatHome[numShards];
- storageStrategy
- .read()
- .subscribe(chatRoom ->
- {
- int shard = chatRoom.getShard();
- if (chatHomes[shard] == null)
- chatHomes[shard] = new SimpleChatHome(chatHomeService, shard);
- });
+ IntStream
+ .of(properties.getInmemory().getOwnedShards())
+ .forEach(shard -> chatHomes[shard] = new SimpleChatHome(chatHomeService, shard));
ShardingStrategy strategy = new KafkaLikeShardingStrategy(numShards);
return new ShardedChatHome(chatHomes, strategy);
}
@ConditionalOnProperty(
prefix = "chat.backend.inmemory",
name = "storage-strategy",
- havingValue = "files",
- matchIfMissing = true)
+ havingValue = "files")
@Configuration
@EnableAutoConfiguration(
exclude = {
--- /dev/null
+package de.juplo.kafka.chat.backend.persistence.storage.nostorage;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import de.juplo.kafka.chat.backend.ChatBackendProperties;
+import de.juplo.kafka.chat.backend.domain.ChatRoom;
+import de.juplo.kafka.chat.backend.domain.ShardingStrategy;
+import de.juplo.kafka.chat.backend.persistence.StorageStrategy;
+import de.juplo.kafka.chat.backend.persistence.inmemory.InMemoryChatRoomService;
+import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.boot.autoconfigure.data.mongo.MongoRepositoriesAutoConfiguration;
+import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import reactor.core.publisher.Flux;
+
+import java.nio.file.Paths;
+import java.time.Clock;
+
+
+@ConditionalOnProperty(
+ prefix = "chat.backend.inmemory",
+ name = "storage-strategy",
+ havingValue = "none",
+ matchIfMissing = true)
+@Configuration
+@EnableAutoConfiguration(
+ exclude = {
+ MongoRepositoriesAutoConfiguration.class,
+ MongoAutoConfiguration.class })
+public class NoStorageStorageConfiguration
+{
+ @Bean
+ public StorageStrategy storageStrategy()
+ {
+ return new StorageStrategy()
+ {
+ @Override
+ public void write(Flux<ChatRoom> chatroomFlux) {}
+
+ @Override
+ public Flux<ChatRoom> read()
+ {
+ return Flux.empty();
+ }
+ };
+ }
+}
@SpringBootTest(
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
properties = {
+ "chat.backend.inmemory.storage-strategy=files",
"chat.backend.inmemory.storage-directory=target/test-classes/data/files",
"chat.backend.inmemory.sharding-strategy=kafkalike",
"chat.backend.inmemory.num-shards=10",
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
properties = {
"chat.backend.inmemory.sharding-strategy=none",
+ "chat.backend.inmemory.storage-strategy=files",
"chat.backend.inmemory.storage-directory=target/test-classes/data/files" })
class InMemoryWithFilesConfigurationIT extends AbstractConfigurationIT
{