Giter VIP home page Giter VIP logo

redis-dqueue's Introduction

redis-dqueue

redis-dqueue is a redis + Java 8 base delayed queue library.

Document

Travis Build License Twitter URL

Feature

  • Push message delay
  • Consumer allowed to try again
  • Based on the message separation of the topic
  • Integrated SpringBoot

Normal Java Application

With Maven

<dependency>
    <groupId>io.github.biezhi</groupId>
    <artifactId>redis-dqueue-core</artifactId>
    <version>0.0.3.ALPHA</version>
</dependency>

Push message and subscribe topic

RDQueue rdQueue = new RDQueue(new Config());

// "hello world" messages sent after 10 seconds
Message<String> message = new Message<>("TEST_TOPIC", "hello world", 10);

// async push delay message
rdQueue.asyncPush(message, (key, throwable) -> log.info("key send ok:" + key));

// subscribe topic
rdQueue.subscribe("TEST_TOPIC", callback());

Callback

private static Callback<String> callback() {
    return new Callback<String>() {
        @Override
        public ConsumeStatus execute(String data) {
            log.info("消费数据:: {}", data);
            return ConsumeStatus.CONSUMED;
        }
    };
}

Spring Boot Application

With Maven

<dependency>
    <groupId>io.github.biezhi</groupId>
    <artifactId>redis-dqueue-spring-boot-starter</artifactId>
    <version>0.0.3.ALPHA</version>
</dependency>

Push message

@Autowired
private RDQueueTemplate rdQueueTemplate;

@GetMapping("/push")
public String push(String id) throws RDQException {
    Message<String> message = new Message<>();
    message.setTopic("order-cancel");
    message.setPayload(id);
    message.setDelayTime(10);
    rdQueueTemplate.asyncPush(message, (s, throwable) -> {
      // TODO async push result
    });
    return "推送成功";
}

Subscribe topic

You need to implement MessageListener, subscribe to the related topic, process delay messages in the execute method.

Ensure that the class was Spring managed.

@Component
public class OrderCancelListener implements MessageListener<String> {
    
    @Override
    public String topic() {
        return "order-cancel";
    }
    
    @Override
    public ConsumeStatus execute(String data) {
        log.info("取消订单: {}", data);
        return ConsumeStatus.CONSUMED;
    }
    
}

Lisence

Apache2

redis-dqueue's People

Contributors

dependabot[bot] avatar hellokaton 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.