optionally pass plugin conf path to persistence plugins, #19822
This commit is contained in:
parent
5b5cf4fc7b
commit
57e59c8496
9 changed files with 126 additions and 36 deletions
|
|
@ -82,11 +82,18 @@ class PersistenceQuery(system: ExtendedActorSystem) extends Extension {
|
|||
def instantiate(args: collection.immutable.Seq[(Class[_], AnyRef)]) =
|
||||
system.dynamicAccess.createInstanceFor[ReadJournalProvider](pluginClass, args)
|
||||
|
||||
instantiate((classOf[ExtendedActorSystem], system) :: (classOf[Config], pluginConfig) :: Nil)
|
||||
instantiate((classOf[ExtendedActorSystem], system) :: (classOf[Config], pluginConfig) ::
|
||||
(classOf[String], configPath) :: Nil)
|
||||
.recoverWith {
|
||||
case x: NoSuchMethodException ⇒ instantiate(
|
||||
(classOf[ExtendedActorSystem], system) :: (classOf[Config], pluginConfig) :: Nil)
|
||||
}
|
||||
.recoverWith { case x: NoSuchMethodException ⇒ instantiate((classOf[ExtendedActorSystem], system) :: Nil) }
|
||||
.recoverWith { case x: NoSuchMethodException ⇒ instantiate(Nil) }
|
||||
.recoverWith {
|
||||
case ex: Exception ⇒ Failure.apply(new IllegalArgumentException(s"Unable to create read journal plugin instance for path [$configPath], class [$pluginClassName]!", ex))
|
||||
case ex: Exception ⇒ Failure.apply(
|
||||
new IllegalArgumentException("Unable to create read journal plugin instance for path " +
|
||||
s"[$configPath], class [$pluginClassName]!", ex))
|
||||
}.get
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ package akka.persistence.query
|
|||
import akka.NotUsed
|
||||
import akka.stream.scaladsl.Source
|
||||
import com.typesafe.config.{ Config, ConfigFactory }
|
||||
import akka.actor.ExtendedActorSystem
|
||||
|
||||
/**
|
||||
* Use for tests only!
|
||||
|
|
@ -29,10 +30,19 @@ class DummyReadJournalForJava(readJournal: DummyReadJournal) extends javadsl.Rea
|
|||
object DummyReadJournalProvider {
|
||||
final val config: Config = ConfigFactory.parseString(
|
||||
s"""
|
||||
|${DummyReadJournal.Identifier} {
|
||||
| class = "${classOf[DummyReadJournalProvider].getCanonicalName}"
|
||||
|}
|
||||
""".stripMargin)
|
||||
${DummyReadJournal.Identifier} {
|
||||
class = "${classOf[DummyReadJournalProvider].getCanonicalName}"
|
||||
}
|
||||
${DummyReadJournal.Identifier}2 {
|
||||
class = "${classOf[DummyReadJournalProvider2].getCanonicalName}"
|
||||
}
|
||||
${DummyReadJournal.Identifier}3 {
|
||||
class = "${classOf[DummyReadJournalProvider3].getCanonicalName}"
|
||||
}
|
||||
${DummyReadJournal.Identifier}4 {
|
||||
class = "${classOf[DummyReadJournalProvider4].getCanonicalName}"
|
||||
}
|
||||
""")
|
||||
}
|
||||
|
||||
class DummyReadJournalProvider extends ReadJournalProvider {
|
||||
|
|
@ -43,3 +53,10 @@ class DummyReadJournalProvider extends ReadJournalProvider {
|
|||
override val javadslReadJournal: DummyReadJournalForJava =
|
||||
new DummyReadJournalForJava(scaladslReadJournal)
|
||||
}
|
||||
|
||||
class DummyReadJournalProvider2(sys: ExtendedActorSystem) extends DummyReadJournalProvider
|
||||
|
||||
class DummyReadJournalProvider3(sys: ExtendedActorSystem, conf: Config) extends DummyReadJournalProvider
|
||||
|
||||
class DummyReadJournalProvider4(sys: ExtendedActorSystem, conf: Config, confPath: String) extends DummyReadJournalProvider
|
||||
|
||||
|
|
|
|||
|
|
@ -28,6 +28,10 @@ class PersistenceQuerySpec extends WordSpecLike with Matchers with BeforeAndAfte
|
|||
"be found by full config key" in {
|
||||
withActorSystem() { system ⇒
|
||||
PersistenceQuery.get(system).readJournalFor[DummyReadJournal](DummyReadJournal.Identifier)
|
||||
// other combinations of constructor parameters
|
||||
PersistenceQuery.get(system).readJournalFor[DummyReadJournal](DummyReadJournal.Identifier + "2")
|
||||
PersistenceQuery.get(system).readJournalFor[DummyReadJournal](DummyReadJournal.Identifier + "3")
|
||||
PersistenceQuery.get(system).readJournalFor[DummyReadJournal](DummyReadJournal.Identifier + "4")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue