Giter VIP home page Giter VIP logo

disruptor-spring-manager's Introduction

Spring managed LMAX Disruptor

This project wraps the amazing LMAX Disruptor and ring buffer components to be used by a Spring managed context. You can create as many disruptor spring beans and all of them will be automatically registered as a JMX MBean.

About LMAX Disruptor

A single threaded High concurrency, low-latency solution by LMAX.

Read more about this in:

Software Prerequisites

  1. JDK 8+
  2. Maven 3+
  3. Git

Versions used

  • Spring: 4.3.x
  • LMAX Disruptor: 3.3.6

Example project

Checkout disruptor-billing with usage examples.

How-to

  1. Create Event Publisher(s) by implementing org.anair.disruptor.pubilsher.EventPublisher
  2. Create Event Processors by implementing com.lmax.disruptor.EventHandler
  3. Create Event Factory to represent the model object stored in the ring buffer
  4. Create Event Translator to publish data to the ring buffer
  5. Create a spring bean to configure and create a disruptor.

Required values:

  • Executor Thread name: Give a name to the thread the disruptor will be working on. This will help in debugging disruptor logs by looking for the thread name.
  • EventFactory: Factory wrapper around the model object. This is used to prepare the ring buffer with the model type objects.
  • EventHandlerChain: Design the dependency barrier and event processor/consumer dependencies in a chained manner.

Default values, if not provided through Spring configuration:

  • Ring buffer size: 1024
  • Producer Type: Single producer
  • Wait Strategy Type: Blocking Wait Strategy

The spring configuration is based on the Consumer Dependency diamond graph that looks like this:

                                       |     journalBillingEventProcessor     |     billingBusinessEventProcessor                 |
                                       |    /                                 |    /                                              |
                                       |   /                                  |   /                                               |
billingEventPublisher -> Ring Buffer ->|  -                                   |  -  corporateBillingBusinessEventProcessor        | -billingOutboundFormattingEventProcessor
                                       |   \                                  |   \                                               |
                                       |    \                                 |    \                                              |
                                       |     billingValidationEventProcessor  |     customerSpecificBillingBusinessEventProcessor |

Spring configuration:

<bean id="billingDisruptor" class="org.anair.disruptor.DefaultDisruptorConfig"
	init-method="init" destroy-method="controlledShutdown">

	<property name="threadName" value="billingThread" />
	<property name="eventFactory">
		<bean
			class="org.anair.billing.disruptor.eventfactory.BillingEvent" />
	</property>
	<property name="eventHandlerChain">
		<array>
			<bean class="org.anair.disruptor.EventHandlerChain" scope="prototype">
				<constructor-arg name="currentEventHandlers">
					<array value-type="com.lmax.disruptor.EventHandler">
						<ref bean="journalBillingEventProcessor" />
						<ref bean="billingValidationEventProcessor" />
					</array>
				</constructor-arg>
				<constructor-arg name="nextEventHandlers">
					<array value-type="com.lmax.disruptor.EventHandler">
						<ref bean="billingBusinessEventProcessor" />
						<ref bean="corporateBillingBusinessEventProcessor" />
						<ref bean="customerSpecificBillingBusinessEventProcessor" />
					</array>
				</constructor-arg>
			</bean>
			
			<bean class="org.anair.disruptor.EventHandlerChain" scope="prototype">
				<constructor-arg name="currentEventHandlers">
					<array value-type="com.lmax.disruptor.EventHandler">
						<ref bean="billingBusinessEventProcessor" />
						<ref bean="corporateBillingBusinessEventProcessor" />
						<ref bean="customerSpecificBillingBusinessEventProcessor" />
					</array>
				</constructor-arg>
				<constructor-arg name="nextEventHandlers">
					<array value-type="com.lmax.disruptor.EventHandler">
						<ref bean="billingOutboundFormattingEventProcessor" />
					</array>
				</constructor-arg>
			</bean>
		</array>
	</property>
</bean>

Logging

Add to log4j.properties of your application to monitor disruptor activities

org.anair.disruptor=INFO 

JMX

1.Create/configure your local JMX MBean server
2.Add the below spring configuration and pass in the mbeanServer bean:

<bean class="org.anair.disruptor.jmx.JmxDisruptorManager" 
	p:mBeanServer-ref="mbeanServer"/> 

3.On application context startup, all Disruptor beans will be automatically identified and registered as MBeans
4.View Disruptor MBeans through JConsole/Visual VM

Design Diagrams

###Disruptor Class diagram Class diagram

disruptor-spring-manager's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  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.