Skip to content

Latest commit

 

History

History
114 lines (88 loc) · 2.98 KB

README.md

File metadata and controls

114 lines (88 loc) · 2.98 KB

disruptor

license central build

library for introducing disruptions to your code to replicate an unstable live environment.

Modules

  • core: core disruptor API
  • spring: spring integration
  • openfeign: feign integration

Links

Usage

Installation

Maven:

<dependency>
    <groupId>org.incendo</groupId>
    <!-- disruptor-core, disruptor-spring, disruptor-openfeign -->
    <artifactId>disruptor-core</artifactId>
    <version>1.0.0</version>
</dependency>

Gradle (Kotlin)

implementation("org.incendo:disruptor-core:1.0.0")

Gradle (Groovy)

implementation 'org.incendo:disruptor-core:1.0.0'

Pure Java

final Disruptor disruptor = Disruptor.builder()
        .group(
                // Creates a new group called "test"...
                "test",
                group -> group
                        .config(
                                // which triggers 25% of the time, and lasts for 5 seconds once triggered
                                DisruptionTrigger.random(0.25f).lasting(Duration.ofSeconds(5L)),
                                config -> config
                                        // running before the method that is disrupted
                                        .mode(DisruptionMode.BEFORE)
                                        // introducing a delay of 5 seconds
                                        .delay(Duration.ofSeconds(5L))
                                        // then throwing an exception
                                        .throwException(ctx -> new RuntimeException("hello :)"))
                        )
        )
        .build();

disruptor.disruptWithoutResult("test", () -> {
    System.out.println("test");
});

OpenFeign

final DisruptorCapability capability = DisruptorCapability.of(
        disruptor,
        "group"
);
Feign.builder()/*...*/.addCapability(capability)/*...*/;

// Or, if using spring-cloud-openfeign:
@Bean
Capability disruptorCapability() {
    return DisruptorCapability(disruptor, "group");
}

Spring

import java.beans.BeanProperty;

@Configuration
public class YourConfig {

    @Bean
    Disruptor disruptor() {
        return Disruptor.builder()/*...*/.build();
    }
}

@Disrupt("group") // You may annotate a class...
public class YourService {
    
    @Disrupt("other-group") //... or a method
    public void yourMethod() {
    }
}