需求:收到银行异步通知,要在2秒内将结果返回银行,同时还要根据银行返回的交易状态更新数据库订单状态和其他业务。
采用disruptor,其实最好使用独立MQ产品。本次用的是disruptor,遇到了一些问题,本文说下disruptor的问题排查。
问题1、消费者不在接收队列消息。
原因:handler程序中throw e ,将异常抛给了disruptor,而我们没有设定com.lmax.disruptor.ExceptionHandler。
解决:法1.handler中不要throw e,而是catch捕获并处理。法2,设定ExceptionHandler
问题2、压测时,ringBufferSize=1024,策略=BlockingWaitStrategy。1个用户连续发,结果到1000笔左右时,就不在执行了,但没报错。于是改成2048,结果到2000笔左右时也不在执行了。
解决:队列设置为1024*1024,就解决了。
原因:
SingleProducerSequencer.java 部分源码:
有些人会说,队列数调在高也可能会出现1024、2048时的阻塞情况,这不是解决问题的根本方法。
的确如此,可通过构建多消费者,使得消费能力尽可能的敢上生产能力。