Handling Deadline outside Aggregate

Hi people,
I’ve been trying to use Deadline and it wasn’t working as I expected until I realised my mistake was defining the @DeadlineHandler outside of the Aggregate.
Like mentioned here:

When scheduling a deadline, the context from where it was scheduled is taken into account. That means a given scheduled deadline will only be triggered in its originating context. Thus any @DeadlineHandler annotated function you wish to be called on a met deadline, must be in the same Aggregate/Saga from which is was scheduled.

Axon calls this Context a Scope. If necessary, implementing and providing your own Scope will allow you to schedule Deadlines in your custom, scoped components.

Is there any reason why it has to be inside the Aggregate? Am I missing some obvious design? Since all our @EventHandler’s are defined in another class I wanted to have the @DeadlineHandler to be defined there as well.

I’m trying to understand how to use the ScopeDescriptor for that but can get me head around it yet. Do you have any example on how to use it?

Thanks!

– Henrique

Hi Henrique,

Yes, this design was definitely intentionally, as a deadline is typically tied to a specific aggregate or saga instance within the system.
Thus the scope of a deadline is narrow and thus intentionally kept within that exact instance.

Take the example that you’d have an Invoice aggregate.
That Invoice needs to be paid by someone, typically with a certain time period within which a notification should be send.
In this scenario, you’d schedule a deadline in your Invoice aggregate.
Upon handling the deadline, you’ll first verify the state of the Invoice aggregate to check, prior to notifying other components that the invoice should still be paid for example.

If you want to notify everything that something has happened, so broadcast this message, that’s when a regular event would be a better fit.
This was the initial point of view of deadlines for framework which is covered with the EventScheduler.

If you’d like to do deadlines to be scheduled from within the context of a given Event Handling Component, then you’d have to make it implement the Scope object.
As you likely encountered, this isn’t a trivial thing; it’s something we have on our mental backlog to resolve for future releases.

For now though, I am guessing the EventScheduler will resolve the problem you’re having.
If not, please send a follow up question on this topic.

Hope this helps you out Henrique!

Cheers,
Steven