springlmax

Configure Long run process using Spring Application Context & lmax disruptors


We have a project that needs long run process to check whether payment has been complied, if so record has to promoted to the next level. Since they are huge number of records to process we decided to use lmax disruptor. What are the options? that we can integrate lmax with Spring Application Context?


Solution

    1. Add bean to Context xml and make lazy-load="false"
    <bean id="noticeReminderBatchProcessorApi" class="lk.scandium.spring.batch.lmax.NoticeReminderBatchProcessor" init-method="init"
              destroy-method="destroy" lazy-init="false"
              p:numberOfThreads="1"
              p:queueWarnLimit="5"/>
    
    private final ExecutorService EXECUTOR = Executors.newFixedThreadPool(1);
        private Disruptor<TransactionEvent> disruptor;
        private RingBuffer<TransactionEvent> ringBuffer;
    
        @Autowired
        private PaymentCompletionHandler paymentCompletionHandler;
        private String numberOfThreads;
        private String queueWarnLimit;
    
        public void processTransaction(PaymentProcessBridge paymentProcessBridge) {
            long sequence = ringBuffer.next();  // Grab the next sequence
            TransactionEvent transactionEvent = ringBuffer.get(sequence);
            transactionEvent.setPaymentProcessBridge(paymentProcessBridge);
            ringBuffer.publish(sequence);
        }
    
    public void init() {
            disruptor = new Disruptor<TransactionEvent>(
                    TransactionEvent.EVENT_FACTORY,
                    1024,
                    EXECUTOR,
                    ProducerType.SINGLE,
                    new SleepingWaitStrategy());
    
            disruptor.handleEventsWith(paymentCompletionHandler);
            ringBuffer = disruptor.start();
        }