com.github.lemfi.kest.rabbitmq.executor.RabbitMQQueueCreationExecution.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of step-rabbitmq Show documentation
Show all versions of step-rabbitmq Show documentation
Backends testing with Kotlin
package com.github.lemfi.kest.rabbitmq.executor
import com.github.lemfi.kest.core.logger.LoggerFactory
import com.github.lemfi.kest.core.model.Execution
import com.github.lemfi.kest.rabbitmq.builder.QueueAndBinding
import com.rabbitmq.client.ConnectionFactory
import java.net.URLEncoder
internal class RabbitMQQueueCreationExecution(
private val queueAndBinding: QueueAndBinding,
private val connection: String,
private val vhost: String,
) : Execution() {
private val encodedVhost: String = URLEncoder.encode(vhost, Charsets.UTF_8)
override fun execute() {
LoggerFactory.getLogger("RABBITMQ-Kest")
.info(
"""
|Queue creation:
|
|vhost: $vhost
|name: ${queueAndBinding.queue}
|
|${
if (queueAndBinding.exchange != null) {
"""bound to exchange:
| exchange: ${queueAndBinding.exchange}
| routing key: ${queueAndBinding.routingKey}""".trimMargin()
} else {
"""bound to default ("") exchange"""
}
}""".trimMargin()
)
ConnectionFactory().also {
it.setUri("$connection/$encodedVhost")
}
.newConnection("kest connection")
.createChannel()
.apply {
queueDeclare(queueAndBinding.queue, false, false, true, mutableMapOf())
if (queueAndBinding.exchange != null && queueAndBinding.routingKey != null)
queueBind(queueAndBinding.queue, queueAndBinding.exchange, queueAndBinding.routingKey)
}
.connection.close()
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy