GithubHelp home page GithubHelp logo

delayedqueue's Introduction

Delayed queue

Build Status

DelayedQueue is a library to enqueue and later handle immutable events. It is written in java on top of reactor and lettuce. Redis is the only available storage engine. Queue doesn't provide durability guarantees but in pair with clusterized redis installation it is suitable for many use cases.

Key features are:

  • event handling is retriable at increased intervals between attempts
  • subscription context could be passed to a handler
  • support for the @PreDestroy lifecycle annotation
  • sending metrics using Micrometer

DelayedQueue are highly opinionated (hence customizable), with very little configuration needed to start using it. If you want more control consider using Netflix's dyno-queue.

Installation

Minimal supported java version is 1.8.

repositories {
    maven { url 'https://jitpack.io' }
}
dependencies {
    implementation 'com.github.fred84:delayedQueue:0.4.0'
}

Examples

Minimal configuration

import static com.github.fred84.queue.DelayedEventService.delayedEventService;

var eventService = delayedEventService().client(redisClient).build();

Full configuration

import static com.github.fred84.queue.DelayedEventService.delayedEventService;

eventService = delayedEventService()
        .client(redisClient)
        .mapper(objectMapper)
        .handlerScheduler(Schedulers.fromExecutorService(executor))
        .schedulingInterval(Duration.ofSeconds(1))
        .schedulingBatchSize(SCHEDULING_BATCH_SIZE)
        .enableScheduling(false)
        .pollingTimeout(POLLING_TIMEOUT)
        .eventContextHandler(new DefaultEventContextHandler())
        .dataSetPrefix("")
        .retryAttempts(10)
        .metrics(new NoopMetrics())
        .refreshSubscriptionsInterval(Duration.ofMinutes(5))
        .build();

Add event handler

eventService.addHandler(DummyEvent.class, e -> Mono.just(true), 1);

Enqueue event

eventService.enqueueWithDelayNonBlocking(new DummyEvent("1"), Duration.ofHours(1)).subscribe();

Close service

eventService.close();

Event context

eventService.addHandler(
        DummyEvent.class,
        e -> Mono
            .subscriberContext()
            .doOnNext(ctx -> {
                Map<String, String> eventContext = ctx.get("eventContext");
                log.info("context key {}", eventContext.get("key"));
            })
            .thenReturn(true),
        1
);

eventService.enqueueWithDelayNonBlocking(new DummyEvent("1"), Duration.ofHours(1), Map.of("key", "value")).subscribe();

Contribution

Contributions are welcome. Just create a pull request.

delayedqueue's People

Contributors

fred84 avatar gafurov0ivan avatar kemnet 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.