Hypothetical question about sagas and retries

Greetings,
I am coding something that does not use Axon, but wanted to see how such a situation might be handled using Axon. It’s a simple sequence of steps that could error out and a retry is warranted. It seems like something a saga would handle, but I could be wrong. So, here goes.

  1. User generates invoice (InvoiceGenerated)
  2. When the invoice is generated, I need to create a notification. However, if nobody is able to receive the notification, then one will not be created and the user who generated the invoice will go and correct the situation. (InvoiceNotificationCreated)
  3. Once the notification has been created, we will need to send it as an email. Not sure of all the potential exceptions that could occur here, but the one that stands out to me is that the email server is down or otherwise unreachable. But, the email needs to go out eventually.

How might something like this be implemented? Thanks!

Hi Brian

Thanks
Marinko

Hi Brian, Marinko,

I am not fully convinced yet a Saga is the way to go in this situation.

From your use case I am feeling that you’re using the Saga to make a service call based on an event occurring, and that’s it.

The Saga is typically used to coordinate actions between several aggregates.

In other terms, a Complex Business Transaction spanning several aggregates (or even bounded contexts).

As it is not a 100% clear from your use case which are aggregates and which aren’t, I can’t with 100% certain state whether you’re doing a ‘Complex Business Transaction’.

If this isn’t the case, a regular Event Handling Component, which as a response to an event occurring tries to send an email, could suffice.

If you however are handling events from several different Aggregates, intermittently storing state and updating those Aggregates if certain action (e.g. sending an email) have succeeded, then a Saga would make a lot of sense.

Now on to the point of triggering an Event which Marinko suggests to - this can be achieved by leveraging the DeadlineManager contained in the framework.

With the DeadlineManager, you can schedule deadline messages, either in a Saga or an Aggregate, which signal a certain deadline has been reached.

For example, that you’d want to retry sending that email if it failed due to a connection issue with the email service.

The Reference Guide is sadly not updated yet with this part; we’re hard at work to resolve that.

If you’re looking for an example, I’d suggest peaking the AbstractDeadlineManagerTestSuite class in the framework repository.

I hope this helps you out Brian.

If not, you are obviously welcome to send more questions regarding this topic.

Cheers,
Steven