In Quarkus, I have this working resource:
@Path("/account")
public class AccountResource {
@CheckedTemplate
static class Templates {
public static native MailTemplateInstance passwordReset(String username, String link);
}
@POST
@Path("/reset")
public Uni<Void> send(@FormParam("email") String username) {
return Templates.passwordReset("John Doe", "https://www.google.it/")
.to(username)
.subject("Password reset request for Generic Application")
.send();
}
}
It fills the Qute template and sends an email in a reactive way. I need to retrieve data from the db using the panache entity, use it to fill up the template, replacing in this case "John Doe"
with the actual name of the user.
I've added a method in the User entity like this:
public static Uni<User> findByUsername(String username) {
return find("username", username).firstResult();
}
but I cannot make it to work together with the email, using within the send method or changing the template to accept Uni<User>
instead of String
. Every time I get this error:
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.
do you use the quarkus-hibernate-reactive-panache
extention? You can't use the blocking variant of the API - quarkus-hibernate-orm-panache
- on the event loop where the AccountResource#send()
is executed.