File tree Expand file tree Collapse file tree 2 files changed +13
-6
lines changed
src/main/kotlin/com/possible_triangle/atheneum_connector Expand file tree Collapse file tree 2 files changed +13
-6
lines changed Original file line number Diff line number Diff line change 11package com.possible_triangle.atheneum_connector
22
3+ import com.rabbitmq.client.ConnectionFactory
34import net.minecraftforge.common.ForgeConfigSpec
45import net.minecraftforge.fml.config.ModConfig
56import thedarkcolour.kotlinforforge.forge.LOADING_CONTEXT
@@ -31,10 +32,14 @@ object Config {
3132 private val rabbitmqUser = builder.define(" user" , " guest" )
3233 private val rabbitmqPass = builder.define(" password" , " guest" )
3334 private val rabbitmqHost = builder.define(" host" , " localhost" )
34- private val rabbitmqPort = builder.define (" port" , " 5672" )
35+ private val rabbitmqPort = builder.defineInRange (" port" , 5672 , 0 , Int . MAX_VALUE )
3536
36- val rabbitMQUrl
37- get() = " amqp://${rabbitmqUser.get()} :${rabbitmqPass.get()} @${rabbitmqHost.get()} :${rabbitmqPort.get()} /"
37+ fun configureRabbitMQ () = ConnectionFactory ().apply {
38+ username = rabbitmqUser.get()
39+ password = rabbitmqPass.get()
40+ host = rabbitmqHost.get()
41+ port = rabbitmqPort.get()
42+ }
3843
3944 init {
4045 builder.pop()
Original file line number Diff line number Diff line change @@ -20,9 +20,11 @@ object RabbitMQ : RecoveryListener, ShutdownListener {
2020 private lateinit var channel: Channel
2121
2222 fun connect () {
23- AtheneumConnector . LOG .info( " Connecting to RabbitMQ " )
23+ val factory = Config . SERVER .configureRabbitMQ( )
2424
25- val connection = ConnectionFactory ().newConnection(Config .SERVER .rabbitMQUrl)
25+ AtheneumConnector .LOG .info(" Connecting to RabbitMQ at amqp://${factory.host} :${factory.port} " )
26+
27+ val connection = factory.newConnection()
2628
2729 connection.addShutdownListener(this )
2830
@@ -64,7 +66,7 @@ object RabbitMQ : RecoveryListener, ShutdownListener {
6466 }
6567
6668 override fun shutdownCompleted (exception : ShutdownSignalException ) {
67- if (exception.isInitiatedByApplication) return
69+ if (exception.isInitiatedByApplication) return
6870 AtheneumConnector .LOG .warn(" RabbitMQ has shutdown, reconnecting... ({})" , exception.message)
6971 }
7072
You can’t perform that action at this time.
0 commit comments