From 0317a894e5dc755338401d3ddc8356e19b46ee1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johan=20Andr=C3=A9n?= Date: Wed, 18 Oct 2023 14:07:26 +0200 Subject: [PATCH] docs: Start from snapshot for drone push projection --- .../src/main/resources/persistence-h2.conf | 4 ++++ .../src/main/resources/persistence-postgres.conf | 2 ++ .../src/main/scala/local/drones/Drone.scala | 5 +++++ .../src/main/scala/local/drones/DroneEvents.scala | 10 +++++++++- 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/samples/grpc/local-drone-control-scala/src/main/resources/persistence-h2.conf b/samples/grpc/local-drone-control-scala/src/main/resources/persistence-h2.conf index 4d27f6e45..ea806a02c 100644 --- a/samples/grpc/local-drone-control-scala/src/main/resources/persistence-h2.conf +++ b/samples/grpc/local-drone-control-scala/src/main/resources/persistence-h2.conf @@ -27,3 +27,7 @@ akka { } } } + +// #startFromSnapshot +akka.persistence.r2dbc.query.start-from-snapshot.enabled = true +// #startFromSnapshot diff --git a/samples/grpc/local-drone-control-scala/src/main/resources/persistence-postgres.conf b/samples/grpc/local-drone-control-scala/src/main/resources/persistence-postgres.conf index 694f3ee02..4ad66bb14 100644 --- a/samples/grpc/local-drone-control-scala/src/main/resources/persistence-postgres.conf +++ b/samples/grpc/local-drone-control-scala/src/main/resources/persistence-postgres.conf @@ -31,3 +31,5 @@ akka { } } } + +akka.persistence.r2dbc.query.start-from-snapshot.enabled = true diff --git a/samples/grpc/local-drone-control-scala/src/main/scala/local/drones/Drone.scala b/samples/grpc/local-drone-control-scala/src/main/scala/local/drones/Drone.scala index a21f89022..f34c82e51 100644 --- a/samples/grpc/local-drone-control-scala/src/main/scala/local/drones/Drone.scala +++ b/samples/grpc/local-drone-control-scala/src/main/scala/local/drones/Drone.scala @@ -96,6 +96,11 @@ object Drone { .receiveSignal { case (_, PostStop) => telemetry.droneEntityPassivated() } + // #startFromSnapshot + .snapshotWhen { (_, event, _) => + event.isInstanceOf[CoarseGrainedLocationChanged] + } + // #startFromSnapshot } // #commandHandler diff --git a/samples/grpc/local-drone-control-scala/src/main/scala/local/drones/DroneEvents.scala b/samples/grpc/local-drone-control-scala/src/main/scala/local/drones/DroneEvents.scala index 4a89af47c..79f178525 100644 --- a/samples/grpc/local-drone-control-scala/src/main/scala/local/drones/DroneEvents.scala +++ b/samples/grpc/local-drone-control-scala/src/main/scala/local/drones/DroneEvents.scala @@ -101,7 +101,15 @@ object DroneEvents { EventProducerSettings(system), // only push coarse grained coordinate changes producerFilter = envelope => - envelope.event.isInstanceOf[Drone.CoarseGrainedLocationChanged]), + envelope.event.isInstanceOf[Drone.CoarseGrainedLocationChanged]) + // #startFromSnapshot + // start from latest drone snapshot and don't replay history + .withStartingFromSnapshots[ + Drone.State, + Drone.CoarseGrainedLocationChanged](state => + Drone.CoarseGrainedLocationChanged( + state.coarseGrainedCoordinates.get)), + // #startFromSnapshot GrpcClientSettings.fromConfig("central-drone-control")) def projectionForPartition(