0
votes

I have two Axon @EventHandler's that need to be processed in a certain order (they have DIFFERENT events to handle). I have read that i need to:

  1. annotate all involved event handlers with org.axonframework.config.ProcessingGroup (order seems only applicable within one processingGroup); annotation is done at class level,
  2. use org.springframework.core.annotation.Order to determine priority; annotation is done also at class level

But even with this annotation, the events are handled in the order that they have been triggered. Or this functionality is only applicable for the same types of events ? Pseudo-code would look like below :

@Component
@RequiredArgsConstructor
@ProcessingGroup("mytest")
@Order(2)
public class Test2RecordProjection {

    @EventHandler
    public void on(Test2CreatedEvent evt) {
    ...
    }
}

@Component
@RequiredArgsConstructor
@ProcessingGroup("mytest")
@Order(1)
public class Test1RecordProjection {

    @EventHandler
    public void on(Test1CreatedEvent evt) {
    ...
    }
}

Axon 4.0

1

1 Answers

2
votes

But even with this annotation, the events are handled in the order that they have been triggered.

That's completely as expected. You're event handling components will receive events in the order as they have been persisted in the EventStore.

The only thing you can do with the @Order annotation, is impose an order in which Event Handling Components within a given Processing Group are called.

Thus the annotation is likely doing it's job, first providing events to your Test1RecordProjection and only after it has seen it cannot handle a given event will it move over to Test2RecordProjection.

This process however does not change in what order the events will be handled, only in what order the event handling components within a Processing Group will be called.