Clarify supervision of singleton actors (#25681)
* Clarify supervision of singleton actors * Document supervision for typed singletons
This commit is contained in:
parent
bc7d77a801
commit
2045a0fbf7
4 changed files with 68 additions and 15 deletions
|
|
@ -160,7 +160,15 @@ with different settings if needed.
|
|||
|
||||
## Supervision
|
||||
|
||||
Sometimes it is useful to add supervision for the Cluster Singleton itself. To accomplish this you need to add a parent supervisor actor which will be used to create the 'real' singleton instance. Below is an example implementation (credit to [this StackOverflow answer](https://stackoverflow.com/a/36716708/779513))
|
||||
There are two actors that could potentially be supervised. For the `consumer` singleton created above these would be:
|
||||
|
||||
* Cluster singleton manager e.g. `/user/consumer` which runs on every node in the cluster
|
||||
* The user actor e.g. `/user/consumer/singleton` which the manager starts on the oldest node
|
||||
|
||||
The Cluster singleton manager actor should not have its supervision strategy changed as it should always be running.
|
||||
However it is sometimes useful to add supervision for the user actor.
|
||||
To accomplish this add a parent supervisor actor which will be used to create the 'real' singleton instance.
|
||||
Below is an example implementation (credit to [this StackOverflow answer](https://stackoverflow.com/a/36716708/779513))
|
||||
|
||||
Scala
|
||||
: @@snip [ClusterSingletonSupervision.scala](/akka-docs/src/test/scala/docs/cluster/singleton/ClusterSingletonSupervision.scala) { #singleton-supervisor-actor }
|
||||
|
|
|
|||
|
|
@ -57,6 +57,23 @@ Scala
|
|||
Java
|
||||
: @@snip [SingletonCompileOnlyTest.java](/akka-cluster-typed/src/test/java/jdocs/akka/cluster/typed/SingletonCompileOnlyTest.java) { #import #singleton }
|
||||
|
||||
## Supervision
|
||||
|
||||
The default @ref[supervision strategy](./fault-tolerance.md) when an exception is thrown is for an actor to be stopped.
|
||||
The above example overrides this to `restart` to ensure it is always running. Another option would be to restart with
|
||||
a backoff:
|
||||
|
||||
|
||||
Scala
|
||||
: @@snip [SingletonCompileOnlySpec.scala](/akka-cluster-typed/src/test/scala/docs/akka/cluster/typed/SingletonCompileOnlySpec.scala) { #backoff}
|
||||
|
||||
Java
|
||||
: @@snip [SingletonCompileOnlyTest.java](/akka-cluster-typed/src/test/java/jdocs/akka/cluster/typed/SingletonCompileOnlyTest.java) { #backoff}
|
||||
|
||||
Be aware that this means there will be times when the singleton won't be running as restart is delayed.
|
||||
See @ref[Fault Tolerance](./fault-tolerance.md) for a full list of supervision options.
|
||||
|
||||
|
||||
## Accessing singleton of another data centre
|
||||
|
||||
TODO
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue