Hi,
I see some other behavior regarding to transaction management as I would expect.
The issue is that I have two database schema’s. One for the event store and one for the read model. So there are also two dataSources and two TransactionManagers defined in spring.
To enable the spring / axon auto configuration I defined the datasource for the event store being the @Primary.
To prevent the event store related transaction manager being used in the projections on the readModel side I registered a default transactionManager in the eventProcessingConfigurer.
In my projection service class I’am using these annotations and this works fine:
@Service
@Transactional(transactionManager = "readModelTransactionManager")
@ProcessingGroup(ORGANIZATION_PROCESSING_GROUP)
class OrganizationProjectionService(private val organizationRepo: OrganizationRepo) {
@EventHandler
fun on(event: OrganizationDetailsUpdatedEvent, @SequenceNumber version: Long) =
organizationRepo.save(event.toEntity(version))
Question is why is the @Transactional(transactionManager = "readModelTransactionManager")
needed, since I registered a defaultTransaction manager in the event processing config?
I would expect Axon to start one transaction for @EventHandler annotated function in the projection service and commit at the end of the function. But when I omit this annotation multiple transactions are started in the event handler. The repository is also annotated with @Transactional(transactionManager = "readModelTransactionManager")
So what is going on, and what is the recommend way to configure this?
Thanks a lot,
Frank
The stack:
- axon framework (axon-bom-4.9.2)
- spring-boot 3.17
- postgres db for event store
- postgres db for readmodel
- using tracking event processors
with this Axon configuration:
@Bean
fun axonTransactionManager(eventStoreTransactionManager: PlatformTransactionManager) =
SpringTransactionManager(eventStoreTransactionManager)
@Autowired
fun defaultTrackingEventProcessors(
eventProcessingConfigurer: EventProcessingConfigurer,
readModelTransactionManager: PlatformTransactionManager,
) {
eventProcessingConfigurer
.registerDefaultTransactionManager { SpringTransactionManager(readModelTransactionManager) }
.usingTrackingEventProcessors()
}