diff --git a/src/main/kotlin/eventDemo/adapter/infrastructureLayer/event/GameEventBusInRabbinMQ.kt b/src/main/kotlin/eventDemo/adapter/infrastructureLayer/event/GameEventBusInRabbinMQ.kt new file mode 100644 index 0000000..fae10c5 --- /dev/null +++ b/src/main/kotlin/eventDemo/adapter/infrastructureLayer/event/GameEventBusInRabbinMQ.kt @@ -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 by BusInRabbitMQ( + connectionFactory, + "GameEvent", + { Json.encodeToString(it) }, + { Json.decodeFromString(it) }, + ), + Comparable { + private val instanceId: UUID = UUID.randomUUID() + + override fun compareTo(other: GameEventBusInRabbinMQ): Int = + compareValues(instanceId, other.instanceId) +} diff --git a/src/main/kotlin/eventDemo/configuration/injection/ConfigureDIInfrastructure.kt b/src/main/kotlin/eventDemo/configuration/injection/ConfigureDIInfrastructure.kt index a04602b..7ab9510 100644 --- a/src/main/kotlin/eventDemo/configuration/injection/ConfigureDIInfrastructure.kt +++ b/src/main/kotlin/eventDemo/configuration/injection/ConfigureDIInfrastructure.kt @@ -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