How to config snapshots in axon 4.X

I downloaded the giftcard-demo from axon package (default configuration with h2 database) and I’m trying to configure snapshots.

import org.axonframework.eventsourcing.*;
import org.axonframework.spring.eventsourcing.SpringAggregateSnapshotterFactoryBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class AxonConfig {

    @Bean
    public SnapshotTriggerDefinition mySnapshotTriggerDefinition(Snapshotter snapshotter) {
        return new EventCountSnapshotTriggerDefinition(snapshotter, 3);
    }

    @Bean public SpringAggregateSnapshotterFactoryBean springAggregateSnapshotterFactoryBean() {
        return new SpringAggregateSnapshotterFactoryBean();
    }
}

I checked on AxonDashboard (http://localhost:8024) and snapshots are never created.

What is wrong?

Thanks,

You have to define the threshold on your application configuration file.

https://github.com/idugalic/digital-restaurant/blob/master/drestaurant-libs/drestaurant-courier/src/main/kotlin/com/drestaurant/courier/domain/SpringCourierConfiguration.kt

Lucas,

It is defined with the number “3”. I don’t understand what you mean.

Could you help me?

I forget to mention that my aggregate has the tag @Aggregate(snapshotTriggerDefinition = “mySnapshotTriggerDefinition”).

The problem still persist.

Hi Gustavo,

You have provided a SnapshotTriggerDefinition bean and set it through the @Aggregate “snapshotTriggerDefinition” field, which typically should suffice to set up snapshotting for an Aggregate.
I’d personally first check whether your application is connected to Axon Server as desired.
Does it show up in the dashboard? Does it shows counts for other messages, like commands, events and queries?

If so, then I’d try to deduce whether the SnapshotTriggerDefinition you’ve set is actually being used.
This could of course be done through debugging, but wrapping the SnapshotTriggerDefinition and adding a log statement on the eventHandled method.

If it’s not being hit, then I am pretty certain it is not being configured, which might come down to a bean naming issue.
You could set the qualifier on the bean creation function of your SnapshotTriggerDefinition, or set the name field in your @Bean annotation to the name you want the bean to have.

Hope this guidance helps you out Gustavo!

Cheers,
Steven