pekko/akka-samples/akka-sample-persistence-java/tutorial/index.html
Konrad 'ktoso' Malawski 3fd240384c +per #15424 Added PersistentView, deprecated View
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
2014-06-26 10:10:09 +02:00

114 lines
4.7 KiB
HTML

<!-- <html> -->
<head>
<title>Akka Persistence Samples in Java</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/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/persistence.html#event-sourcing-java" 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/ProcessorFailureExample.java" class="shortcut">ProcessorFailureExample.java</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/java/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>
<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>