AF5: SequenceNumber for event handler

I am working on migrating an application using AF4 to AF5 (version 5.1.1). The application has an event handler with methods annotated with @EventHandler. The event handler methods have an argument annotated with @SequenceNumber. Here is an example:

@EventHandler public void apply(Renamed event, @SequenceNumber Long version, @Timestamp Instant timestamp) {

When this event handler is called, the version is null. If I define the method argument as a long instead of a Long, the result is a NullPointerException.

I am aware that as documented here, it is only possible to use the SequenceNumber annotation when the event was created from an aggregate. That should be the case in my application.

I have been debugging the problem and it seems that the legacy resource keys (e.g. AGGREGATE_SEQUENCE_NUMBER_KEY) are added to the context in AggregateBasedJpaEventStorageEngine, but when MethodInvokingMessageHandlingMember is called, they are not there.

Can you help me find out, what I am doing wrong?

This was a bug in Axon Framework, @Henrik_Norgaard! It has been addressed in 5.1.2 of Axon Framework. Please give it a try: the @SequenceNumber annotation should work again without any issues.

Root cause to the issue, was that we weren’t copying the context information from the event stream to the ProcessingContext for handling the events. If you’re curious, here’s the fix: [#4647] Propagate all entry resources to per-event ProcessingContext by hatzlj · Pull Request #4669 · AxonIQ/AxonFramework · GitHub