user4081947
user4081947

Reputation: 151

Reactive Mailer - blocking operation on a IO thread

With reactive mailer I am trying to persist if the email was succeeded or not. Here down the code snippet that is not woking:

@Path("atendimentos")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public class AtendimentoResource {
    @Inject
    AtendimentoHistoricoRepository atendimentoHistoricoRepository;
    @Inject
    ReactiveMailer mailer;
    @GET
    public Response findAll(@QueryParam("nome") String nome) {
    AtendimentoHistorico atendimentoHistorico = new AtendimentoHistorico();
       mailer.send(email).subscribe().with(success -> {
           atendimentoHistorico.setEmailEnviado(true);
           atendimentoHistoricoRepository.persist(atendimentoHistorico);
         }, error -> {
       });
    }
}

Here is the thrown exception:

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.

Upvotes: 0

Views: 879

Answers (1)

geoand
geoand

Reputation: 64059

If you want to block, you should use io.quarkus.mailer.Mailer instead of ReactiveMailer.

@Path("atendimentos")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public class AtendimentoResource {
    @Inject
    AtendimentoHistoricoRepository atendimentoHistoricoRepository;
    @Inject
    Mailer mailer;
    @GET
    public Response findAll(@QueryParam("nome") String nome) {
    AtendimentoHistorico atendimentoHistorico = new AtendimentoHistorico();
       mailer.send(email);
       atendimentoHistorico.setEmailEnviado(true);
       atendimentoHistoricoRepository.persist(atendimentoHistorico);
    }
}

Upvotes: 0

Related Questions