create GameEventBusInRabbinMQ and use it as GameEventBus

This commit is contained in:
2025-04-01 21:20:05 +02:00
parent 5f992f887d
commit 9e3c1267bf
2 changed files with 27 additions and 3 deletions

View File

@@ -0,0 +1,25 @@
package eventDemo.adapter.infrastructureLayer.event
import com.rabbitmq.client.ConnectionFactory
import eventDemo.business.event.GameEventBus
import eventDemo.business.event.event.GameEvent
import eventDemo.libs.bus.Bus
import eventDemo.libs.bus.BusInRabbitMQ
import kotlinx.serialization.json.Json
import java.util.UUID
class GameEventBusInRabbinMQ(
private val connectionFactory: ConnectionFactory,
) : GameEventBus,
Bus<GameEvent> by BusInRabbitMQ(
connectionFactory,
"GameEvent",
{ Json.encodeToString(it) },
{ Json.decodeFromString<GameEvent>(it) },
),
Comparable<GameEventBusInRabbinMQ> {
private val instanceId: UUID = UUID.randomUUID()
override fun compareTo(other: GameEventBusInRabbinMQ): Int =
compareValues(instanceId, other.instanceId)
}

View File

@@ -3,7 +3,7 @@ package eventDemo.configuration.injection
import com.rabbitmq.client.ConnectionFactory
import com.zaxxer.hikari.HikariConfig
import com.zaxxer.hikari.HikariDataSource
import eventDemo.adapter.infrastructureLayer.event.GameEventBusInMemory
import eventDemo.adapter.infrastructureLayer.event.GameEventBusInRabbinMQ
import eventDemo.adapter.infrastructureLayer.event.GameEventStoreInPostgresql
import eventDemo.adapter.infrastructureLayer.event.projection.GameListRepositoryInRedis
import eventDemo.adapter.infrastructureLayer.event.projection.GameProjectionBusInMemory
@@ -48,8 +48,7 @@ fun Module.configureDIInfrastructure(config: Configuration) {
password = config.rabbitmq.password
}
}
singleOf(::GameEventBusInMemory) bind GameEventBus::class
singleOf(::GameEventBusInRabbinMQ) bind GameEventBus::class
singleOf(::GameEventStoreInPostgresql) bind GameEventStore::class
singleOf(::GameProjectionBusInMemory) bind GameProjectionBus::class