axonaxon-framework

Axon Framework Execute EventUpcaster


I need to upgrade an event to a new version. This entails removing an old property that is growing (due to a design decision) and is not longer needed.

Having read the documentation available at https://docs.axoniq.io/reference-guide/axon-framework/events/event-versioning and implementing the required parts

@Bean
    public EventUpcasterChain eventUpcasterChain(){
        return new EventUpcasterChain(
                new CurrentLoanBalanceAcceptedEventUpcaster(),
                new InterestCalculatedEventUpcaster()
        );
    }

I cannot seem to get the upcasters to fire the "doUpcast" method. My understanding is that on start up the application will find all old events and convert them to the new version of the events. Is this correct? Or does it only upcast the old events when they are replayed? I am hoping there is a way to do this without replaying all the events.

Versions:

Spring Boot: 2.4.11

Axon Framework: 4.5.4

Update:

After trying to figure out how to remove nodes from the event xml using the upcasters I failed miserably. I must point out that this issue is not an Axon issue but was a poor design decision and a lack of understanding what Axon was doing with the events. The primary lesson is to keep events as simple as possible.

I managed to unload the unnecessary xml from the domain event store using the following query:

update domainevententry
set payload = lo_from_bytea(0, decode(regexp_replace(
                                              subquery.output,
                                              '\<nodeToReplace\>(.*)\<\/nodeToReplace\>',
                                              ''
                                          ), 'escape'))
from (
         SELECT eventidentifier, payloadtype, encode(lo_get(payload::oid), 'escape') as output
         FROM domainevententry
         WHERE eventidentifier in (
             '<id>'
             )
           AND payloadtype = '<payloadType>'
     ) as subquery
where domainevententry.eventidentifier = subquery.eventidentifier;

Solution

  • every upcaster in the upcaster chain is called only when it finds an 'old' event to convert to the new one. New events that are fired are the new version of it, so the upcaster will not be used for that.

    Upcasters are used when:

    In all other cases, it will be the new event, so the upcaster won't have to be fired. The upcaster is there so aggregates can keep being loaded, and projections can be replayed from the beginning of the event store.

    If this is not the case, we need to take a look at the Revision parameter on the old event definition and the new event definition. For example, if the old event had no @Revision annotation, the SimpleSerializedType needs a version of null or it won't match.

    Please include the code of the upcasters if we need to dig further, that would help greatly!