Skip to content

Commit

Permalink
build: use mq credentials [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
tyknkd committed May 16, 2024
1 parent 8787955 commit 440f08a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
2 changes: 2 additions & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ export PROMETHEUS_PORT=9090
export RABBITMQ_HOST=mq
export RABBITMQ_METRICS_PORT=15692
export RABBITMQ_PORT=5672
export RABBITMQ_DEFAULT_USER=rabbituser
export RABBITMQ_DEFAULT_PASS=rabbitpass
export WEBSERVER_DB=webserver_db
export WEBSERVER_HOST=web-server
export WEBSERVER_PORT=8888
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,19 @@ import com.rabbitmq.client.BuiltinExchangeType
import com.rabbitmq.client.Channel

class Exchange(val name: String, val queue: String, val routingKey: String) {
private val user = System.getenv("RABBITMQ_DEFAULT_USER")
private val pass = System.getenv("RABBITMQ_DEFAULT_PASS")
private val mqport = System.getenv("RABBITMQ_PORT")?.toInt()?:5672
private val mqhost = if (System.getenv("OS_ENV") == "container") {
System.getenv("RABBITMQ_HOST")
} else {
"localhost"
}
private val factory = ConnectionFactory().apply {
setUri(getRabbitMqUri())
username = user
password = pass
port = mqport
host = mqhost
}
private val connection = factory.newConnection()
private val durable = true
Expand All @@ -19,14 +30,4 @@ class Exchange(val name: String, val queue: String, val routingKey: String) {
queueBind(queue, name, routingKey)
confirmSelect()
}

private fun getRabbitMqUri(): String {
val port = System.getenv("RABBITMQ_PORT")?:5672
val host = if (System.getenv("OS_ENV") == "container") {
System.getenv("RABBITMQ_HOST")
} else {
"localhost"
}
return "amqp://$host:$port"
}
}
4 changes: 4 additions & 0 deletions compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ services:
image: rabbitmq:3.13-management
container_name: ${RABBITMQ_HOST}
environment:
RABBITMQ_DEFAULT_PASS: ${RABBITMQ_DEFAULT_PASS}
RABBITMQ_DEFAULT_USER: ${RABBITMQ_DEFAULT_USER}
RABBITMQ_LOGS: "-"
ports:
- ${RABBITMQ_PORT}:${RABBITMQ_PORT}
Expand Down Expand Up @@ -190,6 +192,8 @@ services:
POSTGRES_PASSWORD_FILE: /run/secrets/postgres_password
POSTGRES_PORT: ${POSTGRES_PORT}
POSTGRES_USER: ${POSTGRES_USER}
RABBITMQ_DEFAULT_PASS: ${RABBITMQ_DEFAULT_PASS}
RABBITMQ_DEFAULT_USER: ${RABBITMQ_DEFAULT_USER}
RABBITMQ_HOST: ${RABBITMQ_HOST}
RABBITMQ_PORT: ${RABBITMQ_PORT}
WEBSERVER_HOST: ${WEBSERVER_HOST}
Expand Down

0 comments on commit 440f08a

Please sign in to comment.