fix #23618 : Support for persistence dynamic configuration at runtime (#23841)

This commit is contained in:
Prada Souvanlasy 2018-03-26 13:52:31 +02:00 committed by Patrik Nordwall
parent 0a426a7ab0
commit 46c662965f
16 changed files with 918 additions and 144 deletions

View file

@ -2,11 +2,13 @@
* Copyright (C) 2009-2018 Lightbend Inc. <https://www.lightbend.com>
*/
import akka.persistence.PersistentActor
import akka.persistence.{ RuntimePluginConfig, PersistentActor }
import com.typesafe.config.ConfigFactory
object PersistenceMultiDocSpec {
val DefaultConfig = """
val DefaultConfig =
"""
//#default-config
# Absolute path to the default journal plugin configuration entry.
akka.persistence.journal.plugin = "akka.persistence.journal.inmem"
@ -19,9 +21,11 @@ object PersistenceMultiDocSpec {
trait ActorWithDefaultPlugins extends PersistentActor {
override def persistenceId = "123"
}
//#default-plugins
val OverrideConfig = s"""
val OverrideConfig =
s"""
//#override-config
# Configuration entry for the custom journal plugin, see `journalPluginId`.
akka.persistence.chronicle.journal {
@ -43,11 +47,42 @@ object PersistenceMultiDocSpec {
//#override-plugins
trait ActorWithOverridePlugins extends PersistentActor {
override def persistenceId = "123"
// Absolute path to the journal plugin configuration entry in the `reference.conf`.
override def journalPluginId = "akka.persistence.chronicle.journal"
// Absolute path to the snapshot store plugin configuration entry in the `reference.conf`.
override def snapshotPluginId = "akka.persistence.chronicle.snapshot-store"
}
//#override-plugins
//#runtime-config
trait ActorWithRuntimePluginConfig extends PersistentActor with RuntimePluginConfig {
// Variable that is retrieved at runtime, from an external service for instance.
val runtimeDistinction = "foo"
override def persistenceId = "123"
// Absolute path to the journal plugin configuration entry, not defined in the `reference.conf`.
override def journalPluginId = s"journal-plugin-$runtimeDistinction"
// Absolute path to the snapshot store plugin configuration entry, not defined in the `reference.conf`.
override def snapshotPluginId = s"snapshot-store-plugin-$runtimeDistinction"
// Configuration which contains the journal plugin id defined above
override def journalPluginConfig = ConfigFactory.empty().withValue(
s"journal-plugin-$runtimeDistinction",
context.system.settings.config.getValue("journal-plugin") // or a very different configuration coming from an external service.
)
// Configuration which contains the snapshot store plugin id defined above
override def snapshotPluginConfig = ConfigFactory.empty().withValue(
s"snapshot-plugin-$runtimeDistinction",
context.system.settings.config.getValue("snapshot-store-plugin") // or a very different configuration coming from an external service.
)
}
//#runtime-config
}