A PersistentView works the same way as View did previously, except: * it requires an `peristenceId` (no default is provided) * messages given to `receive` are NOT wrapped in Persistent() akka-streams not touched, will update them afterwards on different branch Also solves #15436 by making persistentId in PersistentView abstract. (cherry picked from commit dcafaf788236fe6d018388dd55d5bf9650ded696) Conflicts: akka-docs/rst/java/lambda-persistence.rst akka-docs/rst/java/persistence.rst akka-docs/rst/scala/persistence.rst akka-persistence/src/main/scala/akka/persistence/Persistent.scala akka-persistence/src/main/scala/akka/persistence/View.scala
89 lines
3.4 KiB
HTML
89 lines
3.4 KiB
HTML
<!-- <html> -->
|
|
<head>
|
|
<title>Akka Persistence Samples in Java with Lambdas</title>
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<div>
|
|
<h2>Akka Persistence Samples</h2>
|
|
<p>
|
|
This tutorial contains examples that illustrate a subset of
|
|
<a href="http://doc.akka.io/docs/akka/2.4-SNAPSHOT/java/lambda-persistence.html" target="_blank">Akka Persistence</a> features.
|
|
</p>
|
|
<ul>
|
|
<li>persistent actor</li>
|
|
<li>persistent actor snapshots</li>
|
|
<li>persistent actor recovery</li>
|
|
<li>persistent actor views</li>
|
|
</ul>
|
|
|
|
<p>
|
|
Custom storage locations for the journal and snapshots can be defined in
|
|
<a href="#code/src/main/resources/application.conf" class="shortcut">application.conf</a>.
|
|
</p>
|
|
</div>
|
|
|
|
<div>
|
|
<h2>Persistent actor</h2>
|
|
<p>
|
|
<a href="#code/src/main/java/sample/persistence/PersistentActorExample.java" class="shortcut">PersistentActorExample.java</a>
|
|
is described in detail in the <a href="http://doc.akka.io/docs/akka/2.3-SNAPSHOT/java/lambda-persistence.html#event-sourcing-java-lambda" target="_blank">Event sourcing</a>
|
|
section of the user documentation. With every application run, the <code>ExamplePersistentActor</code> is recovered from
|
|
events stored in previous application runs, processes new commands, stores new events and snapshots and prints the
|
|
current persistent actor state to <code>stdout</code>.
|
|
</p>
|
|
|
|
<p>
|
|
To run this example, go to the <a href="#run" class="shortcut">Run</a> tab, and run the application main class
|
|
<b><code>sample.persistence.PersistentActorExample</code></b> several times.
|
|
</p>
|
|
</div>
|
|
|
|
<div>
|
|
<h2>Persistent actor snapshots</h2>
|
|
<p>
|
|
<a href="#code/src/main/java/sample/persistence/SnapshotExample.java" class="shortcut">SnapshotExample.java</a>
|
|
demonstrates how persistent actors can take snapshots of application state and recover from previously stored snapshots.
|
|
Snapshots are offered to persistent actors at the beginning of recovery, before any messages (younger than the snapshot)
|
|
are replayed.
|
|
</p>
|
|
|
|
<p>
|
|
To run this example, go to the <a href="#run" class="shortcut">Run</a> tab, and run the application main class
|
|
<b><code>sample.persistence.SnapshotExample</code></b> several times. With every run, the state offered by the
|
|
most recent snapshot is printed to <code>stdout</code>, followed by the updated state after sending new persistent
|
|
messages to the persistent actor.
|
|
</p>
|
|
</div>
|
|
|
|
<div>
|
|
<h2>Persistent actor recovery</h2>
|
|
<p>
|
|
<a href="#code/src/main/java/sample/persistence/PersistentActorFailureExample.java" class="shortcut">PersistentActorFailureExample.java</a>
|
|
shows how a persistent actor can throw an exception, restart and restore the state by replaying the events.
|
|
</p>
|
|
|
|
<p>
|
|
To run this example, go to the <a href="#run" class="shortcut">Run</a> tab, and run the application main class
|
|
<b><code>sample.persistence.PersistentActorFailureExample</code></b> several times.
|
|
</p>
|
|
</div>
|
|
|
|
<div>
|
|
<h2>Persistent actor views</h2>
|
|
<p>
|
|
<a href="#code/src/main/java/sample/persistence/ViewExample.java" class="shortcut">ViewExample.java</a> demonstrates
|
|
how a view (<code>ExampleView</code>) is updated with the persistent message stream of a persistent actor
|
|
(<code>ExamplePersistentActor</code>). Messages sent to the persistent actor are scheduled periodically. Views also support
|
|
snapshotting to reduce recovery time.
|
|
</p>
|
|
|
|
<p>
|
|
To run this example, go to the <a href="#run" class="shortcut">Run</a> tab, and run the application main class
|
|
<b><code>sample.persistence.PersistentViewExample</code></b>.
|
|
</p>
|
|
</div>
|
|
|
|
</body>
|
|
</html>
|