https://github.com/hellokaton/redis-dqueue
redis base delay queue
https://github.com/hellokaton/redis-dqueue
delay-queue java8 redis-delay-queue
Last synced: 4 months ago
JSON representation
redis base delay queue
- Host: GitHub
- URL: https://github.com/hellokaton/redis-dqueue
- Owner: hellokaton
- Created: 2019-11-25T14:13:59.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2024-12-03T09:02:49.000Z (about 1 year ago)
- Last Synced: 2024-12-03T10:19:48.625Z (about 1 year ago)
- Topics: delay-queue, java8, redis-delay-queue
- Language: Java
- Size: 76.2 KB
- Stars: 44
- Watchers: 3
- Forks: 12
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# redis-dqueue
`redis-dqueue` is a `redis` + `Java 8` base delayed queue library.
**[Document](https://github.com/biezhi/redis-dqueue/wiki)**
[](https://travis-ci.org/biezhi/redis-dqueue)
[](https://mvnrepository.com/artifact/io.github.biezhi/redis-dqueue)
[](https://github.com/biezhi/redis-dqueue/blob/master/LICENSE)
[](https://twitter.com/biezhii)
## Feature
- Push message delay
- Consumer allowed to try again
- Based on the message separation of the topic
- Integrated SpringBoot
## Normal Java Application
With Maven
```xml
io.github.biezhi
redis-dqueue-core
0.0.3.ALPHA
```
### Push message and subscribe topic
```java
RDQueue rdQueue = new RDQueue(new Config());
// "hello world" messages sent after 10 seconds
Message 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**
```java
private static Callback callback() {
return new Callback() {
@Override
public ConsumeStatus execute(String data) {
log.info("消费数据:: {}", data);
return ConsumeStatus.CONSUMED;
}
};
}
```
## Spring Boot Application
With Maven
```xml
io.github.biezhi
redis-dqueue-spring-boot-starter
0.0.3.ALPHA
```
### Push message
```java
@Autowired
private RDQueueTemplate rdQueueTemplate;
@GetMapping("/push")
public String push(String id) throws RDQException {
Message 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.
```java
@Component
public class OrderCancelListener implements MessageListener {
@Override
public String topic() {
return "order-cancel";
}
@Override
public ConsumeStatus execute(String data) {
log.info("取消订单: {}", data);
return ConsumeStatus.CONSUMED;
}
}
```
## Lisence
[Apache2](LISENCE)