Skip to content

Commit

Permalink
No sweat addition of metrics logging got RabbitMQ backend (#17)
Browse files Browse the repository at this point in the history
* No sweat addition of metrics logging got RabbitMQ backend
* review fix

---------

Co-authored-by: IB <[email protected]>
  • Loading branch information
baitcode and IB authored Nov 8, 2023
1 parent 99bfb3d commit 0a0bdb2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
4 changes: 4 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ dependencies {
isTransitive = true
}


implementation("io.micrometer:micrometer-core:1.11.5")


// postgresql (should be moved out of main bundle)
implementation("org.jetbrains.exposed:exposed-core:$exposedVersion")
implementation("org.jetbrains.exposed:exposed-dao:$exposedVersion")
Expand Down
11 changes: 11 additions & 0 deletions src/main/kotlin/RabbitMQBroker.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@ package com.zamna.kotask
import ExpDelayQuantizer
import IDelayQuantizer
import com.rabbitmq.client.*
import com.rabbitmq.client.impl.MicrometerMetricsCollector
import io.micrometer.core.instrument.logging.LoggingMeterRegistry
import kotlinx.coroutines.runBlocking
import org.slf4j.LoggerFactory

const val HEADERS_PREFIX = "kot-"

class RabbitMQBroker(
uri: String = "amqp://guest:guest@localhost",
metricsPrefix: String? = null,
val delayQuantizer: IDelayQuantizer = ExpDelayQuantizer()
) : IMessageBroker {
private val createdQueues = mutableSetOf<QueueName>()
Expand All @@ -24,8 +27,16 @@ class RabbitMQBroker(

private var logger = LoggerFactory.getLogger(this::class.java)

private var metricsCollector = MicrometerMetricsCollector(
LoggingMeterRegistry { s -> logger.info(s) },
metricsPrefix
)

init {
val factory = ConnectionFactory()
if (metricsPrefix != null) {
factory.metricsCollector = metricsCollector
}
factory.setUri(uri)
connection = factory.newConnection()
channel = connection.createChannel()
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/ScheduleCleaner.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ val cleanScheduleWorker = Task.create("kotask-system-schedule-clean-worker") { c
ctx.taskManager.scheduler.cleanScheduleOlderThan(
Clock.System.now() - Settings.scheduleTTL
)
}
}

0 comments on commit 0a0bdb2

Please sign in to comment.