kostja kostja - 5 months ago 30
Scala Question

How to trigger a PersistentView update externally

According to the docs, triggering a view update externally is supposed to work like this:

view ! Update(await = true|false)

sending and waiting seems not to work though:

view ! Update(await = true) // repeat x times does not help either
val getState = view ? GetState

the view state is not being updated.

asking does not work either - there is no answer to
and the
times out:

val getUpdate = v ? Update(await = true)
val updated = Await.result(getUpdate, 10 seconds)
val getState = view ? GetState

IIUC, processing of
messages is performed by
. Its reception is not logged and I dont know how I can verify the reception and processing.
msgs dont reach the
overridden in my

what does work is setting a very short refresh interval in a

persistence.view.auto-update-interval = 100ms

The debug log shows that the Journal is updating the view:

... a.p.i.e.InMemoryJournalStorage akka://entityViewSpec/user/JournalStorage - received handled message GetJournalEntriesExceptDeleted(ea-ZleUNl1a3N,1,1,9223372036854775807) from Actor[akka://entityViewSpec/temp/$o]

I dont see this log entry when sending
and waiting

after a short sleep, the view is updated, as expected.

val getState = view ? GetState

So how do I trigger a view update externally without running autoupdates all the time?

Akka 2.4.8

Thank you


My mistake was quite simple - not giving the initial msg enough time to be persisted - the
call has been received at a time when the relevant events were not available from the store yet. The autoupdate setting waited for 100ms before updating. On my local machine with in-mem persistence I need to allow about 50ms before dispatching the
. Then give the system some time to fetch and apply the events:

not working:

actor ! MyCommand
view ! Update(await = true)
val getState = view ? GetState


actor ! MyCommand
view ! Update(await = true)
val getState = view ? GetState


I have tried to recreate your issue but mine view is refreshed :/ Check my example: https://github.com/kpbochenek/akka-playground

Run MyPersistentView.scala

auto-update is off

I can see in logs(View actor receives messages persisted by persistent actor):

00:11:35.325 [pw-akka.actor.default-dispatcher-5] INFO  com.kpbochenek.MyActor - persisted! AAAAAAAA
00:11:35.326 [pw-akka.actor.default-dispatcher-9] INFO  com.kpbochenek.MyActor - persisted! 11111111
00:11:37.254 [pw-akka.actor.default-dispatcher-4] INFO  com.kpbochenek.MyView - VIEW READ AAAAAAAA
00:11:37.255 [pw-akka.actor.default-dispatcher-4] INFO  com.kpbochenek.MyView - VIEW READ 11111111