I would use Akka FSM together with PersistentActor
.
You can have these 2 states:
sealed trait State
case object Idle extends State
case object Active extends State
and this data:
sealed trait Data
case object Uninitialized extends Data
final case class Config(config: String) extends Data
you actor will extend FSM[State, Data]
, and will:
startWith(Idle, Uninitialized)
Then you can say that you only accept SetConfig
messages when Idle
:
when(Idle) {
case Event(SetConfig(conf), Uninitialized) =>
goto(Active) using Config(conf)
}
and once you transition to Active
you can receive other messages with:
when(Active) {
case Event(...
// don't forget to start it up in initial state with:
initialize()
Finally on state transitions you can persist your state using regular Akka Persistence patterns.