use GameEventStoreInPostgresql instead of InMemory

This commit is contained in:
2025-03-29 03:31:13 +01:00
parent d9e05e6d9a
commit 7d030204f6
7 changed files with 30 additions and 6 deletions

View File

@@ -1,7 +1,7 @@
name: event-demo-dev name: event-demo-dev
include: include:
- path: - path:
- parts/docker-compose-external.yaml - parts/docker-compose-databases.yaml
- parts/docker-compose-tools.yaml - parts/docker-compose-tools.yaml
- parts/docker-compose-traefik.yaml - parts/docker-compose-traefik.yaml
- envs/docker-compose-dev.yaml - envs/docker-compose-dev.yaml

View File

@@ -1,7 +1,7 @@
name: event-demo-prod name: event-demo-prod
include: include:
- path: - path:
- parts/docker-compose-external.yaml - parts/docker-compose-databases.yaml
- parts/docker-compose-tools.yaml - parts/docker-compose-tools.yaml
- parts/docker-compose-app.yaml - parts/docker-compose-app.yaml
- parts/docker-compose-traefik.yaml - parts/docker-compose-traefik.yaml

View File

@@ -1,5 +1,5 @@
name: event-demo-test name: event-demo-test
include: include:
- path: - path:
- parts/docker-compose-external.yaml - parts/docker-compose-databases.yaml
- parts/docker-compose-port.yaml - parts/docker-compose-port.yaml

View File

@@ -20,6 +20,7 @@ services:
postgresql: postgresql:
image: postgres:17.4 image: postgres:17.4
command: postgres -c 'max_connections=500'
environment: environment:
POSTGRES_PASSWORD_FILE: /run/secrets/postgresql_password POSTGRES_PASSWORD_FILE: /run/secrets/postgresql_password
POSTGRES_USER: event-demo POSTGRES_USER: event-demo

View File

@@ -0,0 +1,21 @@
package eventDemo.adapter.infrastructureLayer.event
import eventDemo.business.entity.GameId
import eventDemo.business.event.GameEventStore
import eventDemo.business.event.event.GameEvent
import eventDemo.libs.event.EventStore
import eventDemo.libs.event.EventStoreInPostgresql
import kotlinx.serialization.json.Json
import javax.sql.DataSource
/**
* A stream to publish and read the played card event.
*/
class GameEventStoreInPostgresql(
dataSource: DataSource,
) : GameEventStore,
EventStore<GameEvent, GameId> by EventStoreInPostgresql(
dataSource,
{ Json.encodeToString(it) },
{ Json.decodeFromString(it) },
)

View File

@@ -3,7 +3,7 @@ package eventDemo.configuration.injection
import com.zaxxer.hikari.HikariConfig import com.zaxxer.hikari.HikariConfig
import com.zaxxer.hikari.HikariDataSource import com.zaxxer.hikari.HikariDataSource
import eventDemo.adapter.infrastructureLayer.event.GameEventBusInMemory import eventDemo.adapter.infrastructureLayer.event.GameEventBusInMemory
import eventDemo.adapter.infrastructureLayer.event.GameEventStoreInMemory import eventDemo.adapter.infrastructureLayer.event.GameEventStoreInPostgresql
import eventDemo.adapter.infrastructureLayer.event.projection.GameListRepositoryInMemory import eventDemo.adapter.infrastructureLayer.event.projection.GameListRepositoryInMemory
import eventDemo.adapter.infrastructureLayer.event.projection.GameProjectionBusInMemory import eventDemo.adapter.infrastructureLayer.event.projection.GameProjectionBusInMemory
import eventDemo.adapter.infrastructureLayer.event.projection.GameStateRepositoryInRedis import eventDemo.adapter.infrastructureLayer.event.projection.GameStateRepositoryInRedis
@@ -31,13 +31,15 @@ fun Module.configureDIInfrastructure(config: Configuration) {
jdbcUrl = config.postgresql.url jdbcUrl = config.postgresql.url
username = config.postgresql.username username = config.postgresql.username
password = config.postgresql.password password = config.postgresql.password
maximumPoolSize = 50
minimumIdle = 20
}.let { }.let {
HikariDataSource(it) HikariDataSource(it)
} }
} bind DataSource::class } bind DataSource::class
singleOf(::GameEventBusInMemory) bind GameEventBus::class singleOf(::GameEventBusInMemory) bind GameEventBus::class
singleOf(::GameEventStoreInMemory) bind GameEventStore::class singleOf(::GameEventStoreInPostgresql) bind GameEventStore::class
singleOf(::GameProjectionBusInMemory) bind GameProjectionBus::class singleOf(::GameProjectionBusInMemory) bind GameProjectionBus::class
single { single {

View File

@@ -15,7 +15,7 @@ import org.junit.jupiter.api.assertThrows
import kotlin.test.assertNotNull import kotlin.test.assertNotNull
@DelicateCoroutinesApi @DelicateCoroutinesApi
class EventStreamInMemoryTest : class EventStreamTest :
FunSpec({ FunSpec({
fun EventStream<EventXTest, IdTest>.with3Events(block: EventStream<EventXTest, IdTest>.(id: IdTest) -> Unit) = fun EventStream<EventXTest, IdTest>.with3Events(block: EventStream<EventXTest, IdTest>.(id: IdTest) -> Unit) =
also { also {