Lud*_*ine 8 asynchronous spring-boot spring-micrometer micrometer-tracing
我正在将 Spring Boot 项目迁移到版本 3。该项目使用异步任务和跟踪。
根据Micrometer GitHub wiki 上的文档,我们尝试像这样定义异步执行器:
@Configuration(proxyBeanMethods = false)
@EnableAsync
class EventProcessingConfig {
@Bean("eventsPublishExecutor")
fun eventsPublishExecutor(): Executor {
val executor =
object : ThreadPoolTaskExecutor() {
override fun initializeExecutor(
threadFactory: ThreadFactory,
rejectedExecutionHandler: RejectedExecutionHandler
): ExecutorService {
val executorService = super.initializeExecutor(threadFactory,
rejectedExecutionHandler)
return ContextExecutorService.wrap(executorService, ContextSnapshot::captureAll)
}
}
with(executor) {
setThreadNamePrefix("processing-events-")
setWaitForTasksToCompleteOnShutdown(true)
setAwaitTerminationSeconds(30)
initialize()
}
return executor
Run Code Online (Sandbox Code Playgroud)
然而,我们仍然失去了追踪。用下面的代码替换 bean 创建使一切按预期工作(尽管没有自定义)
return ContextExecutorService.wrap(
Executors.newSingleThreadExecutor(),
ContextSnapshot::captureAll
)
Run Code Online (Sandbox Code Playgroud)
您知道 Spring Boot 3 的第一个代码有什么问题或缺少什么吗?
| 归档时间: |
|
| 查看次数: |
1709 次 |
| 最近记录: |