Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ReactiveMailer not working #35201

Closed
Neonell opened this issue Aug 4, 2023 · 5 comments
Closed

ReactiveMailer not working #35201

Neonell opened this issue Aug 4, 2023 · 5 comments
Labels
area/mailer kind/bug Something isn't working

Comments

@Neonell
Copy link

Neonell commented Aug 4, 2023

Describe the bug

ReactiveMailer Email are not send or logged anymore.

The normal Mailer service is working fine.

Expected behavior

ReactiveMail send Method with or without attachment should send an email or log the email content in mock modus.

Actual behavior

ReactiveMail send Method with or without attachment is returning without doing anything. The Mail is never sent.
I implemented both, the non reactive version is working fine, Email are logged or sent when the mock mode is disabled.

How to Reproduce?

  1. Create a new service in Quarkus 3.2+
     private final Mailer mailer;
	private final ReactiveMailer reactiveMailer;

	public Uni<Void> sendEmail(String to, String subject, String content) {
		return reactiveMailer.send(
				Mail.withHtml(
						to,
						subject,
						content
				)
		);
	}


	public Void sendEmailNormal(String to, String subject, String content) {
		mailer.send(
				Mail.withHtml(
						to,
						subject,
						content
				)
		);
		return null;
	}
  1. Call the Methods, sendEmailNormal is working, either logging or actually sending the email, the sendEmail Method never send or log anything, just return after the toMailMessage() from the MutinyMailerImpl is called without calling the actual send method. The same method is called by the sendEmailNormal and after the toMailMessage() actually call the send method as expected.
  2. Somehow the send method chained is not called by reactive call.

Output of uname -a or ver

Linux nbdvb144 5.19.0-50-generic #50-Ubuntu SMP PREEMPT_DYNAMIC Mon Jul 10 18:24:29 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux

Output of java -version

openjdk version "17.0.6" 2023-01-17

GraalVM version (if different from Java)

No response

Quarkus version or git rev

3.2.2.Final

Build tool (ie. output of mvnw --version or gradlew --version)

Apache Maven 3.8.8

Additional information

No response

@Neonell Neonell added the kind/bug Something isn't working label Aug 4, 2023
@quarkus-bot
Copy link

quarkus-bot bot commented Aug 4, 2023

/cc @cescoffier (mailer)

@gastaldi
Copy link
Contributor

gastaldi commented Aug 4, 2023

How are you performing the call to the reactive API? Are you subscribing to the returned Uni<Void>?

@Neonell
Copy link
Author

Neonell commented Aug 4, 2023

Hello @gastaldi ,

No I don't do it explicitly, I'm using the CountDownLatch Class in order to wait for the operation to complete in my test:

                CountDownLatch latch = new CountDownLatch(1);
		// Call the asynchronous method
		mailService.sendEmail(TO, SUBJECT, HTML_CONTENT);

		// Wait for the asynchronous operation to complete
		boolean completed = latch.await(2, TimeUnit.SECONDS);
		Assertions.assertTrue(completed);

This is not a rest endpoint but an internal Service that should be called when needed to notify user about different actions. Maybe that's the difference and I'm pretty new to Asynchronous programming. For now I just tried to write a test, then I tried to bind the method in a Synchronous Rest Endpoint and I wrotted an Asynchronous Document upload and download solution but throug a rest endpoint. Maybe that's the difference.

Thank you for the response I'm gonna read about subscription in java. I know the subscribe mechanisms from Angular but not the one from Java.

And the solution was in the subscrition:

mailService.sendEmail(TO, SUBJECT, HTML_CONTENT).subscribe().with(
				(item) -> latch.countDown()
		, failure -> {
			// Handle any failure if needed
		});

It works now, and I understand why the call was never made. Sorry for that :(

Cheers,
Frédéric

@gastaldi gastaldi closed this as not planned Won't fix, can't repro, duplicate, stale Aug 4, 2023
@gastaldi
Copy link
Contributor

gastaldi commented Aug 4, 2023

You're welcome! If you have any problems, feel free to start a discussion thread at https://github.com/quarkusio/quarkus/discussions instead ;)

@Neonell
Copy link
Author

Neonell commented Aug 4, 2023

Oh merci beaucoup, that's really nice I'm pretty new flying out of the wildfly world to the quarkus one. It's really good to know. And yeah I can almost guess that the powerfull Resteasy library auto-scan Rest resources to identify the async one. It probably auto-create some subscription when a rest call is received.

Next time I ask in the discussions topic instead. Thank you for beeing nice :) I wish you all the best!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/mailer kind/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants