DisruptorCommandBus concurrency errors when using CachingEventSourcingRepository and PessimisticLockFactory


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:

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


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,


Hi Allard,

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

Best regards,