Comments (9)
I dont understand why you wrap the Rest Client call into withContext
? Quarkus REST Client supports suspend functions so you can simply mark your REST endpoints suspendable. Another option is to use https://smallrye.io/smallrye-mutiny/latest/guides/kotlin/ and use awaitSuspending
on the returned Uni
.
from quarkus.
@mschorsch got it, makes sense, thanks
from quarkus.
/cc @geoand (kotlin)
from quarkus.
@mschorsch due by using withContext(Dispatchers.IO) ensuring that such operations run on a thread pool optimized for I/O, preventing the main thread or other critical threads from being blocked. For example database calls, network calls
from quarkus.
@DarthRevanXX The idea of reactive programming (Mutiny, Vert.x Futures/Promises, CompletionFuture, Kotlin Coroutines, ...) is simplified by being able to process many requests with just a few threads (Vert.x IO threads). Using a separate thread pool works against this idea and is not necessary and counterproductive in the case of the REST client.
from quarkus.
@mschorsch , sorry for leaving this ticket w/o attention for a few weeks.
So let's cross-check what we've got here to conclude the discussion and close the ticket.
- Even if the issue appears to be related to Quarkus changing class loaders in and out of the coroutine's scope with migration to 3.9 it is not what we are about to "fix" here as it works as intended.
- What we need to fix is how we use Quarkus rest clients with suspension functions.
To do so we need to move from:
suspend fun getExtensions(id: String?) : List<Extension> {
return withContext(Dispatchers.IO) {
extensionsService.getByIdAsUni(id)
}.awaitSuspending().toList()
}
To this:
suspend fun getExtensions(id: String?): List<Extension> {
return extensionsService.getByIdAsUni(id)
.awaitSuspending().toList()
}
Please confirm if I got everything right 🙏
from quarkus.
I have tested your reproducer but could not reproduce the error you reported. Everything worked as desired without explicitly setting the classloader.
Even if the issue appears to be related to Quarkus changing class loaders in and out of the coroutine's scope with migration to 3.9 it is not what we are about to "fix" here as it works as intended.
I'm not part of the Quarkus team so I can't speak for the Quarkus team but I guess so. @geoand ist that right?
What we need to fix is how we use Quarkus rest clients with suspension functions.
Yes, that is more efficient. Another option is to mark the methods directly as suspendable in the rest client.
@Path("/extensions")
@Named("ExtensionsService")
@RegisterRestClient(configKey = "extensions-api")
interface ExtensionsService {
@GET
suspend fun getById(@RestQuery id: String?): Set<Extension>
}
// ...
@ApplicationScoped
class CoService(
@Named("ExtensionsService")
@RestClient
private val extensionsService: ExtensionsService
) {
suspend fun getExtensions(id: String?): List<Extension> {
return extensionsService.getById(id).toList()
}
}
from quarkus.
I'm not part of the Quarkus team so I can't speak for the Quarkus team but I guess so. @geoand ist that right?
Seems correct to me
from quarkus.
Yes, that is more efficient. Another option is to mark the methods directly as suspendable in the rest client.
+1
from quarkus.
Related Issues (20)
- Hibernate Inheritance not persisting to database table HOT 4
- Quarkus exits without showing thrown exception when using `-H:ThrowMissingRegistrationErrors=` HOT 1
- Not all Micrometer metrics are available when exporting with Json HOT 3
- Quarkus 3.10 issue with OpenTelemetry? HOT 7
- Customize list of exceptions to unwrap in resteasy-reactive HOT 9
- Performance Issue with MP Rest Client HOT 3
- Kotlin junit ParameterizedTest with list as argument, not working anymore (3.13.0.CR1) HOT 6
- OpenAPI generates wrong example for URLs HOT 3
- ClassCast Exception with Quarkus Hibernate HOT 2
- Our Nightly Quarkus build deploy to Nexus was failing after the gradle upgrade to 8.9 HOT 3
- Update examples to use org.htmlunit:htmlunit HOT 5
- Core module is using a mix of traditional `@ConfigRoot` and `@ConfigMapping` HOT 5
- Support for Demonstrating Proof of Possession (DPoP) in quarkus-oidc HOT 1
- Add OIDC response filters HOT 1
- Quarkus JaCoCo in CD/CI error Error while instrumenting io/quarkus/test/common/*
- Sort identity providers by priority in QuarkusIdentityProviderManagerImpl HOT 3
- ArrayIndexOutOfBoundsException occurred when i was serializing data from redis with quarkus redis extension HOT 6
- Incorrect data in the ReactiveDatasourceHealthCheck being set when the connection is down HOT 1
- Narayana throws an exception when working with the latest MSSQL server
- Native Image run issue with XML Changelog quarkus-liquibase HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from quarkus.