Git Product home page Git Product logo

disruptor-example's Introduction

#disruptor example 环境:JDK version:1.6 disruptor:3.3.6

disruptor可以简单的看做是内存MQ(内存消息队列)

image

  • producer:生产事件
  • disruptor(确切的说是里面的ring buffer):存放事件
  • EventHandler:处理事件,进行业务逻辑
  • 对于一个事件,所有的EventHandler都能接收到,也就是说一个事件消息会被处理多次(也可以使用wokerpool只让一个消息处理一次,后面会说)

代码示例

没有顺序,并行执行

step1、step2、step3三个处理器都会接收到消息而且执行没有先后顺序 测试类:example_basic.ParallelEventHandlersMain image

有先后依赖顺序执行

step1、step2、step3 三个步骤会严格按照顺序执行 测试类example_basic.DependenciesChainMain image

菱形顺序

step1-1、step1-2之间没有顺序,但是step2会等到step1-1、step2-1都执行完后才会执行 测试类example_basic.DependenciesDiamondMain image

链式依赖顺序

chain1、chain2之间没有依赖关系,but chain1中的 step1-1、step1-2有先后关系、chain12中的 step2-1、step2-2有先后关系。测试类example_basic.DependenciesMultiChainMain image

异常处理

异常需要设置setDefaultExceptionHandler,要不然处理器抛出异常后,就不会再处理事件了。测试类example_other.SimulationExceptionMain

监控disruptor的负载

调用ringBuffer.remainingCapacity()查看还有多少没使用,测试类example_other.MonitorDisruptorMain

disruptor-example's People

Contributors

yanglikun avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.