LMAX's disruptor. How to define multi EventHandlerGroup?

279 Views Asked by At

I want to handle different event with multi-EventHandleGroup?I can't find example with that.thanks... it's the code:

  executorService = Executors.newFixedThreadPool(threadPoolSize);
  disruptor = new Disruptor<>(new DefaultEventFactory(), 
  ringBufferSize, executorService
     , ProducerType.SINGLE, new BlockingWaitStrategy());
  EventHandlerGroup<OrderEvent> orderEventEventHandlerGroup = 
  disruptor.handleEventsWith(
     new OrderEventHandle(rabbitTemplate));
  orderEventEventHandlerGroup.then(new 
  MoveEventFromProcessing(redisService))
     .then(new EventClearHandle());

I want to add another event and I want to handle it with another EventHandleGroup like:

cancelEventDisruptor.handleEventsWith(new 
CancelOrderHandle()).then(new MoveEventFromProcessing(redisService))
     .then(new EventClearHandle());
1

There are 1 best solutions below

0
On

All eventHandlers see all messages. To achieve what you are looking for your OrderEventHandle and CancelOrderHandle need to be able to establish the type of event seen and ignore the ones which do not apply to them.

In the example code you are also setting up two complete handling chains. You would be better advised to have a single MoveEventFromProcessing gated (see SequenceBarrier) on both the OrderEventHandle and CancelOrderHandle and then gate the EventClearHandle on that. So the topology would look like

Producer -> RB -> OrderEventHandle -> MoveEventFromProcessing -> EventClearHandle \-> CancelEventHandle /