0
I’m using oracle database as event store and Subscribing Event Processor
, when an exception is thrown in one of the event handlers, I want the events to be rolled back, but that does not happen.
Here’s where I have looked
Axon FrameWork: How to rollback in the domain_event_entry table
Spring boot Axon complete rollback
Axon 3-Spring Boot Transaction Management
and of course the docs
My setup (axon 4.9 and Spring)
@Configuration
public class AxonConfig {
// omitting other configuration methods...
public void configureProcessorDefault(EventProcessingConfigurer processingConfigurer) {
processingConfigurer.usingSubscribingEventProcessors();
processingConfigurer.registerDefaultListenerInvocationErrorHandler(configuration -> PropagatingErrorHandler.INSTANCE);
}
@Bean
public CommandBus commandBus(MeterRegistry meterRegistry) {
TransactionManager transactionManager = springTransactionManager();
SimpleCommandBus commandBus = SimpleCommandBus
.builder()
.transactionManager(transactionManager)
.rollbackConfiguration(RollbackConfigurationType.ANY_THROWABLE)
.build();
commandBus.registerHandlerInterceptor(new TransactionManagingInterceptor < > (transactionManager));
return commandBus;
}
@Bean public EventStorageEngine eventStorageEngine() {
return JdbcEventStorageEngine
.builder()
.snapshotSerializer(xStreamSerializer)
.upcasterChain(upcasterChain)
.persistenceExceptionResolver(persistenceExceptionResolver())
.eventSerializer(eventSerializer)
.connectionProvider(new SpringDataSourceConnectionProvider(dataSource))
.transactionManager(springTransactionManager())
.build();
}
}
public class Aggregate {
@CommandHandler
public void handle(MyCommand command,
UnitOfWork parent) {
apply(new CommandCalled());
}
public class ProjectionHandler {
@EventHandler
public void on(CommandCalled event,
UnitOfWork child) {
throw new RuntimeException();
}
commandGateway.sendAndWait(new MyCommand());
one observation is that the parent of UnitOfWork
in the event handler is the one in the command handler, I’ve tried CurrentUnitOfWork.get().rollback()
but it didnt work