Open pkozakCC opened 11 months ago
/cc @evanchooly (kotlin), @geoand (kotlin)
Do you have some example of what exactly you are trying to do? I am asking because I would like to get a sense of what problem we are trying to solve here.
Thanks
The author would like to have a possibility to modify the CoroutineContext before calling the resteasy reactive endpoint, with the aim of storing additional data in the CoroutineContext. This data would then be automatically available via the CoroutineContext in all suspendable resteasy reactive endpoints. The advantage of the CoroutineContext is that it is automatically propagated by the Kotlin coroutines and therefore no longer needs to be managed by the user. A typical use case is the use of the MDC (https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-slf4j/kotlinx.coroutines.slf4j/-m-d-c-context/). In this case, the author probably wants to pass the tenantId for all resteasy reactive resources.
+1
The author would like to have a possibility to modify the CoroutineContext before calling the resteasy reactive endpoint, with the aim of storing additional data in the CoroutineContex
Yeah, I get that. What I want to see is some pseudo-example of what this would be used for
@geoand here's what I'd like to do.
@GET
suspend fun getIt(id: Int): It {
MDC.put("get.id", id)
return withContext(Dispatcher.IO) {
dao.getIt(id)
}
}
With a default coroutine context (or something like it). I could set it up as
fun defaultSetup(rootContext: Context): Context {
return rootContext.plus(MDCContext())
}
This would propagate MDC values through coroutine calls (which is what I want to do).
In order to do this as of now, I have to do something like this on every endpoint
fun getIt(id: Int): It = withContext(MDCContext()) {
return@withContext etc()
}
Thanks for the update!
@cogman I think I have an idea of how to make this work, but what would be super helpful in testing it would be if you could attach a sample application where you are using the feature you mention above.
Thanks
@cogman ^
Discussed in https://github.com/quarkusio/quarkus/discussions/36738