I’m an Axon newbie using the framework to prototype an event sourcing solution.
I started by defining aggregates, commands, and event handlers for my domain objects which all went fairly smoothly and worked more or less as expected. I noted that when my prototype starts, events replay to rehydrate existing objects which is expected and desired based on how I understand the design pattern.
Now I’m moving on to define a saga which is interacting with some external components. My saga handles certain event types and then executes some actions which have side effects (i.e. not idempotent behavior). I think I understand that sagas are not expected to replay events when the application restarts for this reason. Initially, I found that the sagas did replay events on restart and determined that I needed to include a token store in my configuration to persist the position in the event stream that was last processed. Having done so, I now see that my saga doesn’t replay events on restart (good…mission accomplished), but neither does my event handler (hmmm…problem).
Getting the Axon configuration set up properly to accomplish the desired semantics is not for the faint of heart. Not sure where I’m going wrong, so I’d like to buy a vowel. Here’s what my configuration looks like now:
Configurer configurer = DefaultConfigurer.defaultConfiguration(); // // Set up the token store // MysqlDataSource datasource = new MysqlDataSource(); datasource.setPassword(***********); datasource.setUser(**********); datasource.setServerName(**********); datasource.setDatabaseName("tokenstore"); JdbcTokenStore tokenStore = JdbcTokenStore.builder() .connectionProvider(new DataSourceConnectionProvider(datasource)) .serializer(XStreamSerializer.defaultSerializer()) .build(); tokenStore.createSchema(new GenericTokenTableFactory()); configurer.registerComponent(TokenStore.class, conf -> tokenStore); // // Register Aggregates // configurer.configureAggregate(AggregateConfigurer.defaultConfiguration(AxonObjective.class) .configureRepository(c -> EventSourcingRepository.builder(AxonObjective.class) .eventStore(c.eventStore()) .build()) ); // // Register Event Handlers // NOTE: Order is significant. Event handlers are invoked in the order they are added // configurer.registerEventHandler(conf -> new ObjectiveEventHandler()); // // Register Sagas // configurer.eventProcessing().registerSaga(ObjectiveTaskScheduler.class); // // Create configuration and start the framework // configuration = configurer.buildConfiguration(); configuration.start(); // // Grab important configuration components for easy access later // commandGateway = configuration.commandGateway(); eventStore = configuration.eventStore();