Coder Social home page Coder Social logo

Comments (9)

mschorsch avatar mschorsch commented on July 26, 2024 1

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.

DarthRevanXX avatar DarthRevanXX commented on July 26, 2024 1

@mschorsch got it, makes sense, thanks

from quarkus.

quarkus-bot avatar quarkus-bot commented on July 26, 2024

/cc @geoand (kotlin)

from quarkus.

DarthRevanXX avatar DarthRevanXX commented on July 26, 2024

@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.

mschorsch avatar mschorsch commented on July 26, 2024

@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.

Sic4Parvis9Magna avatar Sic4Parvis9Magna commented on July 26, 2024

@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.

  1. 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.
  2. 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.

mschorsch avatar mschorsch commented on July 26, 2024

@Sic4Parvis9Magna

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.

geoand avatar geoand commented on July 26, 2024

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.

geoand avatar geoand commented on July 26, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.