是否有可能提供手动实例化为持久性actor的存储插件(用于日记和快照)? (而不是引用那些通过配置硬编码的那些 . )换句话说,而不是override journal and snapshot plugin ids. as described by Multiple persistence plugin configurations from the manual,我想这样做:

trait ActorWithOverridePlugins extends PersistentActor {

  override def persistenceId = "123"

  /* Not real. */
  override def journalPlugin = new JournalPlugin()

  /* Not real. */
  override def snapshotPlugin = new SnapshotPlugin()

}

为了简要解释我的用例,我想编写一个可参数化的插件,它将透明地存储case类 . 它将通过任何读取和写入(来自Play Framework的JSON库)的实现来实例化,适用于任何特定持久性actor可能处理的案例类 .

在前面的示例的基础上,它可能看起来像这样(为清晰起见,显式类型):

case class Event(timestamp:Long, message:String)

val format:Format[Event] = Json.format[Event]

trait EventsActor extends PersistentActor {

  override def persistenceId = "events"

  /* Not real. Also, should be a singleton. */
  override def journalPlugin = new HypotheticalJournalPlugin[Event](format)

  /* Not real. Also, should be a singleton. */
  override def snapshotPlugin = new HypotheticalSnapshotPlugin[Event](format)

}

为我可能想要处理的每种类型编写配置是可行的,但是冗长而痛苦 .