-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
doc: reduce db connections with SliceRangeShardAllocationStrategy
- Loading branch information
Showing
9 changed files
with
108 additions
and
28 deletions.
There are no files selected for viewing
7 changes: 0 additions & 7 deletions
7
core/src/test/scala/akka/persistence/r2dbc/CborSerializable.scala
This file was deleted.
Oops, something went wrong.
7 changes: 0 additions & 7 deletions
7
core/src/test/scala/akka/persistence/r2dbc/JsonSerializable.scala
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
docs/src/test/java/jdocs/home/sharding/ShardingDocExample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Copyright (C) 2024 Lightbend Inc. <https://www.lightbend.com> | ||
*/ | ||
package jdocs.home.sharding; | ||
|
||
//#sharding-init | ||
import akka.actor.typed.ActorSystem; | ||
import akka.actor.typed.Behavior; | ||
import akka.cluster.sharding.typed.SliceRangeShardAllocationStrategy; | ||
import akka.cluster.sharding.typed.javadsl.ClusterSharding; | ||
import akka.cluster.sharding.typed.javadsl.Entity; | ||
import akka.cluster.sharding.typed.javadsl.EntityTypeKey; | ||
import akka.persistence.Persistence; | ||
|
||
//#sharding-init | ||
|
||
public class ShardingDocExample { | ||
public static class DeviceEntity { | ||
public interface Command { | ||
} | ||
|
||
public static final EntityTypeKey<Command> ENTITY_TYPE_KEY = | ||
EntityTypeKey.create(Command.class, "device"); | ||
|
||
public static Behavior<Command> create(String deviceId) { | ||
return null; | ||
} | ||
} | ||
|
||
public static void example() { | ||
ActorSystem<?> system = null; | ||
|
||
//#sharding-init | ||
ClusterSharding.get(system).init(Entity.of(DeviceEntity.ENTITY_TYPE_KEY, entityContext -> | ||
DeviceEntity.create(entityContext.getEntityId())) | ||
.withMessageExtractor(new SliceRangeShardAllocationStrategy.ShardBySliceMessageExtractor<>( | ||
DeviceEntity.ENTITY_TYPE_KEY.name(), Persistence.get(system))) | ||
.withAllocationStrategy(new SliceRangeShardAllocationStrategy(10, 0.1))); | ||
//#sharding-init | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
38 changes: 38 additions & 0 deletions
38
docs/src/test/scala/docs/home/sharding/ShardingDocExample.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright (C) 2024 Lightbend Inc. <https://www.lightbend.com> | ||
*/ | ||
package docs.home.sharding | ||
|
||
//#sharding-init | ||
import akka.actor.typed.ActorSystem | ||
import akka.actor.typed.Behavior | ||
import akka.cluster.sharding.typed.SliceRangeShardAllocationStrategy | ||
import akka.cluster.sharding.typed.SliceRangeShardAllocationStrategy.ShardBySliceMessageExtractor | ||
import akka.cluster.sharding.typed.scaladsl.ClusterSharding | ||
import akka.cluster.sharding.typed.scaladsl.Entity | ||
import akka.cluster.sharding.typed.scaladsl.EntityTypeKey | ||
import akka.persistence.Persistence | ||
|
||
//#sharding-init | ||
|
||
object ShardingDocExample { | ||
object DeviceEntity { | ||
sealed trait Command | ||
|
||
val EntityKey: EntityTypeKey[Command] = | ||
EntityTypeKey[Command]("DeviceEntity") | ||
|
||
def apply(deviceId: String): Behavior[Command] = ??? | ||
} | ||
|
||
val system: ActorSystem[_] = ??? | ||
|
||
//#sharding-init | ||
ClusterSharding(system).init( | ||
Entity(DeviceEntity.EntityKey)(entityContext => DeviceEntity(entityContext.entityId)) | ||
.withMessageExtractor( | ||
new ShardBySliceMessageExtractor[DeviceEntity.Command](DeviceEntity.EntityKey.name, Persistence(system))) | ||
.withAllocationStrategy(new SliceRangeShardAllocationStrategy(10, 0.1))) | ||
//#sharding-init | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters