Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use config for numberOfProjectionInstances instead of val override #392

Merged
merged 1 commit into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
# override this to use custom settings for the default query plugin
net.sc8s.akka.components.persistence.projection.r2dbc.default = ${akka.persistence.r2dbc}

net.sc8s.akka.components.persistence.projection.r2dbc.default.connection-factory = ${akka.persistence.r2dbc.postgres}
net.sc8s.akka.components.persistence.projection.r2dbc {
default = ${akka.persistence.r2dbc}
default {
connection-factory = ${akka.persistence.r2dbc.postgres}
# this is only used for sharded entities. singleton entities will always have only one instance
# must be a whole number divisor of numberOfSlices [by default 1024].
numberOfProjectionInstances = 1
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ private[r2dbc] trait R2dbcProjection extends EventSourcedT.ProjectionT {
_: EventSourcedT#EventSourcedBaseComponentT
with EventSourcedT#BaseComponent =>

val numberOfProjectionInstances = 1

// override this if you e.g. want to use a readonly endpoint for the projections https://discuss.lightbend.com/t/r2dbc-projections-use-read-only-hot-standby-replicas-for-projections-query/10860 . or override it in the config to customize all projections
val readJournalPluginId = "net.sc8s.akka.components.persistence.projection.r2dbc.default.query"
}
Expand All @@ -47,6 +45,7 @@ trait R2dbcShardedProjection extends R2dbcProjection {
projection: Projection[EventT, ComponentContextS with ComponentContext.Projection],
actorSystem: ActorSystem[_]
): ManagedProjection[EventEnvelope[EventT]] = {
val numberOfProjectionInstances = actorSystem.settings.config.getInt(s"${readJournalPluginId.stripSuffix(".query")}.numberOfProjectionInstances")
val sliceRanges = EventSourcedProvider.sliceRanges(actorSystem, readJournalPluginId, numberOfProjectionInstances)

val projectionIds = sliceRanges.map(sliceRange =>
Expand Down Expand Up @@ -151,7 +150,7 @@ trait R2dbcSingletonProjection extends R2dbcProjection {
new ManagedProjection[EventEnvelope[EventT]](
projection.name,
projectionIds,
numberOfProjectionInstances,
1, // singleton projection parallelism is currently limited to 1 due to the EventsByPersistenceIdSourceProvider
new ProjectionStatusObserver[EventEnvelope[EventT]]()(actorSystem) {
override def extractSequenceNr(envelope: EventEnvelope[EventT]) = envelope.sequenceNr

Expand Down