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

@ -4,28 +4,85 @@
package jdocs.persistence;
import akka.persistence.AbstractPersistentActor;
import akka.persistence.RuntimePluginConfig;
import akka.persistence.UntypedPersistentActor;
import com.typesafe.config.Config;
import com.typesafe.config.ConfigFactory;
public class PersistenceMultiDocTest {
//#default-plugins
abstract class ActorWithDefaultPlugins extends UntypedPersistentActor {
abstract class AbstractPersistentActorWithDefaultPlugins extends AbstractPersistentActor {
@Override
public String persistenceId() { return "123"; }
public String persistenceId() {
return "123";
}
}
//#default-plugins
//#override-plugins
abstract class ActorWithOverridePlugins extends UntypedPersistentActor {
abstract class AbstractPersistentActorWithOverridePlugins extends AbstractPersistentActor {
@Override
public String persistenceId() { return "123"; }
public String persistenceId() {
return "123";
}
// Absolute path to the journal plugin configuration entry in the `reference.conf`
@Override
public String journalPluginId() { return "akka.persistence.chronicle.journal"; }
public String journalPluginId() {
return "akka.persistence.chronicle.journal";
}
// Absolute path to the snapshot store plugin configuration entry in the `reference.conf`
@Override
public String snapshotPluginId() { return "akka.persistence.chronicle.snapshot-store"; }
public String snapshotPluginId() {
return "akka.persistence.chronicle.snapshot-store";
}
}
//#override-plugins
//#runtime-config
abstract class AbstractPersistentActorWithRuntimePluginConfig extends AbstractPersistentActor implements RuntimePluginConfig {
// Variable that is retrieved at runtime, from an external service for instance.
String runtimeDistinction = "foo";
@Override
public String persistenceId() {
return "123";
}
// Absolute path to the journal plugin configuration entry in the `reference.conf`
@Override
public String journalPluginId() {
return "journal-plugin-" + runtimeDistinction;
}
// Absolute path to the snapshot store plugin configuration entry in the `reference.conf`
@Override
public String snapshotPluginId() {
return "snapshot-store-plugin-" + runtimeDistinction;
}
// Configuration which contains the journal plugin id defined above
@Override
public Config journalPluginConfig() {
return ConfigFactory.empty().withValue(
"journal-plugin-" + runtimeDistinction,
getContext().getSystem().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
public Config snapshotPluginConfig() {
return ConfigFactory.empty().withValue(
"snapshot-plugin-" + runtimeDistinction,
getContext().getSystem().settings().config().getValue("snapshot-store-plugin") // or a very different configuration coming from an external service.
);
}
}
//#runtime-config
}

View file

@ -20,6 +20,7 @@ import akka.stream.javadsl.Sink;
import akka.stream.javadsl.Source;
import akka.util.Timeout;
import com.typesafe.config.ConfigFactory;
import docs.persistence.query.MyEventsByTagPublisher;
import org.reactivestreams.Subscriber;
import scala.concurrent.duration.FiniteDuration;