configure rabbitMQ ConnectionFactory

This commit is contained in:
2025-03-31 01:39:57 +02:00
parent e8fb80b646
commit 650e964e48
4 changed files with 40 additions and 0 deletions

View File

@@ -13,10 +13,18 @@ fun appKoinModule(config: Configuration) =
data class Configuration(
val redisUrl: String,
val postgresql: Postgresql,
val rabbitmq: RabbitMQ,
) {
data class Postgresql(
val url: String,
val username: String,
val password: String,
)
data class RabbitMQ(
val url: String,
val port: Int,
val username: String,
val password: String,
)
}

View File

@@ -1,5 +1,6 @@
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
@@ -38,6 +39,16 @@ fun Module.configureDIInfrastructure(config: Configuration) {
}
} bind DataSource::class
single {
ConnectionFactory().apply {
host = config.rabbitmq.url
port = config.rabbitmq.port
virtualHost = virtualHost
username = config.rabbitmq.username
password = config.rabbitmq.password
}
}
singleOf(::GameEventBusInMemory) bind GameEventBus::class
singleOf(::GameEventStoreInPostgresql) bind GameEventStore::class
singleOf(::GameProjectionBusInMemory) bind GameProjectionBus::class

View File

@@ -29,6 +29,13 @@ fun ApplicationConfig.configuration() =
username = getProperty("postgresql.username"),
password = getProperty("postgresql.password"),
),
rabbitmq =
Configuration.RabbitMQ(
url = getProperty("rabbitmq.url"),
port = getProperty("rabbitmq.port").toInt(),
username = getProperty("rabbitmq.username"),
password = getProperty("rabbitmq.password"),
),
)
private fun ApplicationConfig.getProperty(path: String): String =

View File

@@ -26,4 +26,18 @@ postgresql {
password = "changeit"
password = ${?POSTGRESQL_PASSWORD}
}
rabbitmq {
url = "localhost"
url = ${?RABBITMQ_URL}
port = "5672"
port = ${?RABBITMQ_PORT}
username = "event-demo"
username = ${?RABBITMQ_USERNAME}
password = "changeit"
password = ${?RABBITMQ_PASSWORD}
}