Skip to content

Commit

Permalink
docs: add explanation of fixing leader setting
Browse files Browse the repository at this point in the history
  • Loading branch information
nyamada-tis committed Nov 17, 2022
1 parent b6e0030 commit d99c78b
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions docs/implementation_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,30 @@ AtLeastOnceComplete.askTo(
)
```

### Fixing leader actor every shard

By default, all raft actors can become a Leader.
You can fix a Leader actor every shard by setting a sticky leader.

```scala
import akka.actor.typed.ActorSystem
import lerna.akka.entityreplication.typed._

val system: ActorSystem[_] = ???
val clusterReplication = ClusterReplication(system)

// Settings for sticky leader. Only a raft actor which have role "replica-group-1" can become Leader in shard given id "1"
val settings =
ClusterReplicationSettings(system)
.withStickyLeaders(Map("1" -> "replica-group-1"))

val entity =
ReplicatedEntity(BankAccountBehavior.TypeKey)(entityContext => BankAccountBehavior(entityContext))
.withSettings(settings)

clusterReplication.init(entity)
```

### Configuration

On the command side, the related settings are defined at `lerna.akka.entityreplication`(except `lerna.akka.entityreplication.raft.eventsourced`) in [reference.conf](/src/main/resources/reference.conf).
Expand Down

0 comments on commit d99c78b

Please sign in to comment.