Skip to content

Commit

Permalink
Avoid changing the global context registry and instead create our own…
Browse files Browse the repository at this point in the history
… for virtual threads use case
  • Loading branch information
asibross committed Sep 16, 2024
1 parent 8069d80 commit e426ce7
Showing 1 changed file with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -331,13 +331,6 @@ open class DgsAutoConfiguration(
@ConditionalOnClass(name = ["reactor.core.publisher.Flux"])
open fun fluxReactiveDataFetcherResultProcessor(): FluxDataFetcherResultProcessor = FluxDataFetcherResultProcessor()

@Bean
@ConditionalOnMissingBean
open fun dgsMicrometerContextRegistry(): ContextRegistry =
ContextRegistry
.getInstance()
.registerThreadLocalAccessor(Slf4jThreadLocalAccessor())

/**
* JDK 21+ only - Creates the dgsAsyncTaskExecutor which is used to run data fetchers automatically wrapped in CompletableFuture.
* Can be provided by other frameworks to enable context propagation.
Expand All @@ -347,8 +340,15 @@ open class DgsAutoConfiguration(
@ConditionalOnJava(JavaVersion.TWENTY_ONE)
@ConditionalOnMissingBean(name = ["dgsAsyncTaskExecutor"])
@ConditionalOnProperty(name = ["dgs.graphql.virtualthreads.enabled"], havingValue = "true", matchIfMissing = false)
open fun virtualThreadsTaskExecutor(contextRegistry: ContextRegistry): AsyncTaskExecutor {
open fun virtualThreadsTaskExecutor(): AsyncTaskExecutor {
LOG.info("Enabling virtual threads for DGS")

val contextRegistry =
ContextRegistry()
.loadContextAccessors()
.loadThreadLocalAccessors()
.registerThreadLocalAccessor(Slf4jThreadLocalAccessor())

val executor = SimpleAsyncTaskExecutor("dgs-virtual-thread-")
executor.setVirtualThreads(true)
executor.setTaskDecorator(
Expand Down

0 comments on commit e426ce7

Please sign in to comment.