DisruptorCommandBus concurrency errors when using CachingEventSourcingRepository and PessimisticLockFactory

Hi,

I wanted to add cached repository support. From my attempts it looks like when I want to keep PessimisticLockFactory it is only possible when SimpleCommandBus is used.

With SimpleCommandBus everything works nicely, but here’s what’s happening when I switch to DisruptorCommandBus.

Axon: 4.2

Bean definitions:

@Bean
public CommandBus customCommandBus(TransactionManager transactionManager, AxonConfiguration axonConfiguration) {
    DisruptorCommandBus commandBus =
        DisruptorCommandBus.builder()
            .transactionManager(transactionManager)
            .messageMonitor(axonConfiguration.messageMonitor(DisruptorCommandBus.class, "commandBus"))
            .build();
    commandBus.registerHandlerInterceptor(new CorrelationDataInterceptor<>(axonConfiguration.correlationDataProviders()));
    commandBus.registerHandlerInterceptor(new LoggingInterceptor());
    commandBus.registerDispatchInterceptor(new LoggingInterceptor());
    return commandBus;
}

Update:

Just to make it 100% clear: the code sample was from JDK’s ReentrantLock.

Hi Derek,

the DisruptorCommandBus works differently than the other CommandBus implementations. It has a couple of performance optimizations which require it to use a special Repository implementation. Instead of creating your own, you should use the DisruptorCommandBus to create them. See the various DisruptorCommandBus.createRepository(…) methods.

Kind regards,

twitter-icon_128x128.png

Hi Allard,

thank you for this valuable response, this clarifies a lot.

Best regards,
Darek