Prioritizing handling of messages

Hi,

I have the following situation:

  • Data arrives in a stream and each chunk of data results in a command for Aggregate A or B.
  • They both create an Event, also of type A or B.
  • The events are picked up by seperate Saga’s for either A or B.
  • Each saga will issue a command. Command A and B end up the same processing group.
  • The processing group has a tracking event processor with 10 segments.

I need to prioritize in such a way that if there are commands of type A, they are processed first and all commands of type B are processed iff there are no commands of type A to process.

This seems promising:
https://apidocs.axoniq.io/4.5/org/axonframework/config/EventProcessingConfigurer.html#assignHandlerTypesMatching-java.lang.String-int-java.util.function.Predicate-

But I have no idea how to use it and if it is even relevant. No examples or mentions in the docs.

Hi Rafiek, hope you’re doing fine.

The bit you’re referring to is the prioritization of assignment rules when defining if an Event Handling Component (like a Saga) should be attached to Event Processor, foo, bar, or baz. So, that’ll not give you what you’re looking for.

What you are looking for, is giving a priority to commands on the CommandBus. Although we have a solution, there’s a caveat. The solution works for Axon Server at the moment and that’s it. We introduced the so-called CommandPriorityCalculator there as an idea as we got some requests for scenarios like you’re describing.

Not many, though.
Hence why it’s not been ported to the SimpleCommandBus, AsynchronousCommandBus, DisruptorCommandBus, or DistributedCommandBus.
Yet, though.
I feel there’s merit in this.

Long story short: if you’re using Axon Server, you can define a CommandPriorityCalculator bean that implements this for you. If you’re not, we’ll have to investigate what we can do.

In the case of the latter, would you be able to specify the scenario in a bit more detail to me? Perhaps I can find a way into the framework to get this done easily enough without Axon Server.

Hi Steven,

We have now built a service that pre-checks and routes events based on an identifier. It checks if a saga for that identifier exists. If not then it starts the saga for that identifier, if it does exist then it routes the event to the existing saga. The saga then keeps a list of ordered events and handles them in the order/priority we desire.