Custom SequencingPolicy

Hello,

We have an application doing file management where a file is a collection of a lot of different subconcepts.

Because a file and its related subconcepts can get really big in terms of number of events we:

  • modelled each subconcept as an aggregate
  • modelled file itself as an aggregate which just contains some basic overall data.

We have some services that consume these events using tracking event processors handling events in parallel.
The easiest for those services would be to handle all events related to one specific file and its subconcepts in order of insertion into the event store.

Is the best way to do this writing a custom SequencingPolicy?
If the answer to the above question is yes what is the best way to add the id of the file on each event of a subconcept so that we can correlate on that? Do we need to add it as field on the event or is there metadata where we can store it that is accessible in a SequencingPolicy?

For the moment the id of the file is only inside the data of the first event of each subconcept.

Thanks,
Robin

Hi Robin,

Since you want to process events in sequential order per file and subconcept (which are aggregates) it looks like you could use SequentialPerAggregate sequencing policy. This policy is configured by default.

Could be that I didn’t understand your question correctly, so please let me know.

Anyway, if you decide on writing your own sequencing policy and your events do not have the necessary data, you can add it to meta-data. You can leverage this information in your custom sequencing policy implementation since this is the method signature that needs to be overridden:

Object getSequenceIdentifierFor(T event)

Hope this helps!

Cheers,
Milan.

Hi Milan,

No the SequentialPerAggregatePolicy does not work. Because what I need is:

SubConceptA for File 1
Event 1
Event 3

SubConceptB for File 1
Event 2
Event 4

SubConceptA for File 2
Event 5

I need an event stream for file 1 with
Event 1
Event 2
Event 3
Event 4

and an event stream for file 2 with
Event 5

I looked a bit further into the type T of the SequencingPolicy and I see it is the EventMessage. So I can get the metadata from there idd.

Thanks,
Robin

Hi Robin,

I understand what you mean now. The problem is that your events are applied on SubConcept aggregates and SequentialPerAggregate will not work for you. Unfortunately, Axon does not come with a sequencing policy that suits your needs. Good luck with custom implementation and let us know if there are some issues we can help you with!

Cheers,
Milan.