Home > Enterprise >  BlockingOperationNotAllowedException - You have attempted to perform a blocking operation on a IO th
BlockingOperationNotAllowedException - You have attempted to perform a blocking operation on a IO th

Time:07-29

I'm making a GRPC service in my quarkus app and when I try to make a request on my method I get this error:

UNKNOWN: io.quarkus.runtime.BlockingOperationNotAllowedException - You have attempted to perform a blocking operation on a IO thread. This is not allowed, as blocking the IO thread will cause major performance issues with your application. If you want to perform blocking EntityManager operations make sure you are doing it from a worker thread.

So I read in this article that I should add the annotation @Blocking to use the worker thread.

After putting it, i got the same error.

There is my code:

GRPCService

    @Override
    @Blocking
    public Uni<MerchantGRPC> findById(idMerchantGRPC request) {

        // Find in database the merchant (getting error in this)
        MerchantDTO merchantDTO =     merchantService.findById(request.getId());

        return Uni.createFrom().item(fromMerchantDTOtoMerchantGRPC(merchantDTO));
    }

Edit

Service in my proto

    service Greeter {
      rpc SayHello (HelloRequest) returns (HelloReply) {}
      rpc findById (idMerchantGRPC) returns (MerchantGRPC) {}
    }

Dependencies

    <dependency>
          <groupId>io.quarkus</groupId>
          <artifactId>quarkus-arc</artifactId>
        </dependency>
    <dependency>
          <groupId>io.quarkus</groupId>
          <artifactId>quarkus-resteasy-reactive</artifactId>
    </dependency>
    <dependency>
          <groupId>io.quarkus</groupId>
          <artifactId>quarkus-junit5</artifactId>
          <scope>test</scope>
    </dependency>
    <dependency>
          <groupId>io.rest-assured</groupId>
          <artifactId>rest-assured</artifactId>
          <scope>test</scope>
    </dependency>
    <dependency>
          <groupId>io.quarkus</groupId>
          <artifactId>quarkus-resteasy-reactive</artifactId>
    </dependency>
    <dependency>
          <groupId>io.quarkus</groupId>
          <artifactId>quarkus-smallrye-openapi</artifactId>
    </dependency>
    <dependency>
          <groupId>io.quarkus</groupId>
          <artifactId>quarkus-hibernate-orm-panache</artifactId>
    </dependency>
    <dependency>
          <groupId>io.quarkus</groupId>
          <artifactId>quarkus-jdbc-mysql</artifactId>
    </dependency>
    <dependency>
          <groupId>io.quarkus</groupId>
          <artifactId>quarkus-resteasy-reactive-jackson</artifactId>
    </dependency>
    <dependency>
          <groupId>org.mapstruct</groupId>
          <artifactId>mapstruct</artifactId>
          <version>1.5.2.Final</version>
    </dependency>
    <dependency>
          <groupId>org.mapstruct</groupId>
          <artifactId>mapstruct-processor</artifactId>
          <version>1.5.2.Final</version>
    </dependency>
    <dependency>
          <groupId>io.quarkus</groupId>
          <artifactId>quarkus-hibernate-validator</artifactId>
    </dependency>
    <dependency>
          <groupId>io.quarkus</groupId>
          <artifactId>quarkus-junit5-mockito</artifactId>
          <scope>test</scope>
    </dependency>
    <dependency>
          <groupId>io.rest-assured</groupId>
          <artifactId>rest-assured</artifactId>
          <scope>test</scope>
    </dependency>
    <dependency>
          <groupId>io.quarkus</groupId>
          <artifactId>quarkus-grpc</artifactId>
    </dependency>

Do you have any idea that could help ?

CodePudding user response:

There is no goot reason do use a Uni in this case. It would be far easier to just do:

@Override
public MerchantGRPC findById(idMerchantGRPC request) {

    // Find in database the merchant (getting error in this)
    MerchantDTO merchantDTO = merchantService.findById(request.getId());

    return fromMerchantDTOtoMerchantGRPC(merchantDTO);
}

CodePudding user response:

So I decided to use the default gRPC API instead of the Mutiny API because @Blocked don't seems to change the thread to worker pool for my method (Blocked usage). After some changings I got the same error but it works when i used @Blocked on the method (this time the annotation seems to do his job).

  • Related