Created
November 27, 2023 16:54
-
-
Save diegolirio/58d9c82dea72f3477455b0df6da941c4 to your computer and use it in GitHub Desktop.
RabbitMQ with Distributed-Tracing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.distributed.tracing | |
import jakarta.annotation.PostConstruct | |
import org.slf4j.LoggerFactory | |
import org.springframework.amqp.rabbit.annotation.EnableRabbit | |
import org.springframework.amqp.rabbit.annotation.RabbitListener | |
import org.springframework.amqp.rabbit.config.ContainerCustomizer | |
import org.springframework.amqp.rabbit.core.RabbitTemplate | |
import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer | |
import org.springframework.beans.factory.annotation.Autowired | |
import org.springframework.context.annotation.Bean | |
import org.springframework.context.annotation.Configuration | |
import org.springframework.messaging.handler.annotation.Payload | |
import org.springframework.stereotype.Component | |
@Component | |
class DistributedTracingConsumer { | |
private val log = LoggerFactory.getLogger(javaClass) | |
@RabbitListener(queues = ["\${queue.name}"]) | |
fun receive(@Payload fileBody: String) { | |
log.info("message=$fileBody") | |
} | |
} | |
/** | |
* Ref.: | |
* https://github.com/micrometer-metrics/micrometer-samples/blob/main/rabbitmq-consumer/src/main/java/com/example/micrometer/ManualConfiguration.java | |
* | |
*/ | |
@EnableRabbit | |
@Configuration(proxyBeanMethods = false) | |
class ManualConfiguration { | |
@Bean | |
fun containerCustomizer(): ContainerCustomizer<SimpleMessageListenerContainer> { | |
return ContainerCustomizer { container: SimpleMessageListenerContainer -> container.setObservationEnabled(true) } | |
} | |
@Autowired lateinit var rabbitTemplate: RabbitTemplate | |
@PostConstruct | |
fun setup() { | |
rabbitTemplate.setObservationEnabled(true) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment