(cherry picked from commit 02351e32f110a8c4a249f0f3f84bae5898d1a836) Conflicts: akka-samples/akka-sample-persistence-java-lambda/tutorial/index.html akka-samples/akka-sample-persistence-java/tutorial/index.html akka-samples/akka-sample-persistence-scala/build.sbt akka-samples/akka-sample-persistence-scala/src/main/scala/sample/persistence/ConversationRecoveryExample.scala akka-samples/akka-sample-persistence-scala/src/main/scala/sample/persistence/PersistentActorExample.scala akka-samples/akka-sample-persistence-scala/src/main/scala/sample/persistence/ProcessorChannelExample.scala akka-samples/akka-sample-persistence-scala/src/main/scala/sample/persistence/ProcessorChannelRemoteExample.scala akka-samples/akka-sample-persistence-scala/src/main/scala/sample/persistence/SnapshotExample.scala akka-samples/akka-sample-persistence-scala/src/main/scala/sample/persistence/StreamExample.scala akka-samples/akka-sample-persistence-scala/tutorial/index.html
115 lines
4.7 KiB
HTML
115 lines
4.7 KiB
HTML
<!-- <html> -->
|
|
<head>
|
|
<title>Akka Persistence Samples with Scala</title>
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<div>
|
|
<p>
|
|
This tutorial contains examples that illustrate a subset of
|
|
<a href="http://doc.akka.io/docs/akka/2.4-SNAPSHOT/scala/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/scala/sample/persistence/PersistentActorExample.scala" class="shortcut">PersistentActorExample.scala</a>
|
|
is described in detail in the <a href="http://doc.akka.io/docs/akka/2.3-SNAPSHOT/scala/persistence.html#event-sourcing" 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/scala/sample/persistence/SnapshotExample.scala" class="shortcut">SnapshotExample.scala</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/scala/sample/persistence/PersistentActorFailureExample.scala" class="shortcut">PersistentActorFailureExample.scala</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>Processor failure handling</h2>
|
|
<p>
|
|
<a href="#code/src/main/scala/sample/persistence/ProcessorFailureExample.scala" class="shortcut">ProcessorFailureExample.scala</a>
|
|
shows how a processor can delete persistent messages from the journal if they threw an exception. Throwing an exception
|
|
restarts the processor and replays messages. In order to prevent that the message that caused the exception is replayed,
|
|
it is marked as deleted in the journal (during invocation of <code>preRestart</code>). This is a common pattern in
|
|
command-sourcing to compensate write-ahead logging of messages.
|
|
</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.ProcessorFailureExample</code></b> several times.
|
|
</p>
|
|
|
|
<p>
|
|
<a href="http://doc.akka.io/docs/akka/2.4-SNAPSHOT/scala/persistence.html#event-sourcing" target="_blank">Event sourcing</a>
|
|
on the other hand, does not persist commands directly but rather events that have been derived from received commands
|
|
(not shown here). These events are known to be successfully applicable to current processor state i.e. there's
|
|
no need for deleting them from the journal. Event sourced processors usually have a lower throughput than command
|
|
sourced processors, as the maximum size of a write batch is limited by the number of persisted events per received
|
|
command.
|
|
</p>
|
|
</div>
|
|
|
|
<div>
|
|
<h2>Processor views</h2>
|
|
<h2>Persistent actor views</h2>
|
|
<p>
|
|
<a href="#code/src/main/scala/sample/persistence/ViewExample.scala" class="shortcut">ViewExample.scala</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.ViewExample</code></b>.
|
|
</p>
|
|
</div>
|
|
|
|
|
|
</body>
|
|
</html>
|