fix and improve ProjectionSnapshotRepositoryInRedis
This commit is contained in:
+6
-3
@@ -10,6 +10,7 @@ import eventDemo.business.event.projection.gameList.apply
|
||||
import eventDemo.business.event.projection.gameState.GameState
|
||||
import eventDemo.libs.event.projection.ProjectionSnapshotRepositoryInMemory
|
||||
import eventDemo.libs.event.projection.SnapshotConfig
|
||||
import io.github.oshai.kotlinlogging.withLoggingContext
|
||||
|
||||
/**
|
||||
* Manages [projections][GameList], their building and publication in the [bus][GameProjectionBus].
|
||||
@@ -30,9 +31,11 @@ class GameListRepositoryInMemory(
|
||||
|
||||
init {
|
||||
eventBus.subscribe { event ->
|
||||
projectionsSnapshot
|
||||
.applyAndPutToCache(event)
|
||||
.also { projectionBus.publish(it) }
|
||||
withLoggingContext("event" to event.toString()) {
|
||||
projectionsSnapshot
|
||||
.applyAndPutToCache(event)
|
||||
.also { projectionBus.publish(it) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+9
-3
@@ -10,6 +10,7 @@ import eventDemo.business.event.projection.gameState.GameStateRepository
|
||||
import eventDemo.business.event.projection.gameState.apply
|
||||
import eventDemo.libs.event.projection.ProjectionSnapshotRepositoryInMemory
|
||||
import eventDemo.libs.event.projection.SnapshotConfig
|
||||
import io.github.oshai.kotlinlogging.withLoggingContext
|
||||
|
||||
/**
|
||||
* Manages [projections][GameState], their building and publication in the [bus][GameProjectionBus].
|
||||
@@ -31,9 +32,11 @@ class GameStateRepositoryInMemory(
|
||||
init {
|
||||
// On new event was received, build snapshot and publish it to the projection bus
|
||||
eventBus.subscribe { event ->
|
||||
projectionsSnapshot
|
||||
.applyAndPutToCache(event)
|
||||
.also { projectionBus.publish(it) }
|
||||
withLoggingContext("event" to event.toString()) {
|
||||
projectionsSnapshot
|
||||
.applyAndPutToCache(event)
|
||||
.also { projectionBus.publish(it) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,4 +56,7 @@ class GameStateRepositoryInMemory(
|
||||
*/
|
||||
override fun getUntil(event: GameEvent): GameState =
|
||||
projectionsSnapshot.getUntil(event)
|
||||
|
||||
override fun count(gameId: GameId): Int =
|
||||
projectionsSnapshot.count(gameId)
|
||||
}
|
||||
|
||||
+9
-3
@@ -10,6 +10,7 @@ import eventDemo.business.event.projection.gameState.GameStateRepository
|
||||
import eventDemo.business.event.projection.gameState.apply
|
||||
import eventDemo.libs.event.projection.ProjectionSnapshotRepositoryInRedis
|
||||
import eventDemo.libs.event.projection.SnapshotConfig
|
||||
import io.github.oshai.kotlinlogging.withLoggingContext
|
||||
import kotlinx.serialization.json.Json
|
||||
import redis.clients.jedis.UnifiedJedis
|
||||
|
||||
@@ -38,9 +39,11 @@ class GameStateRepositoryInRedis(
|
||||
init {
|
||||
// On new event was received, build snapshot and publish it to the projection bus
|
||||
eventBus.subscribe { event ->
|
||||
projectionsSnapshot
|
||||
.applyAndPutToCache(event)
|
||||
.also { projectionBus.publish(it) }
|
||||
withLoggingContext("event" to event.toString()) {
|
||||
projectionsSnapshot
|
||||
.applyAndPutToCache(event)
|
||||
.also { projectionBus.publish(it) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,4 +63,7 @@ class GameStateRepositoryInRedis(
|
||||
*/
|
||||
override fun getUntil(event: GameEvent): GameState =
|
||||
projectionsSnapshot.getUntil(event)
|
||||
|
||||
override fun count(gameId: GameId): Int =
|
||||
projectionsSnapshot.count(gameId)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user