An open API service indexing awesome lists of open source software.

https://github.com/guoshiqiufeng/spring-cloud-stream-redis

spring cloud stream for redis
https://github.com/guoshiqiufeng/spring-cloud-stream-redis

messaging redis spring-cloud-stream spring-cloud-stream-redis

Last synced: 6 months ago
JSON representation

spring cloud stream for redis

Awesome Lists containing this project

README

        

## spring-cloud-stream-redis

[![Maven central](https://img.shields.io/maven-central/v/io.github.guoshiqiufeng.cloud/spring-cloud-starter-stream-redis.svg?style=flat-square)](https://search.maven.org/search?q=g:io.github.guoshiqiufeng.cloud%20AND%20a:spring-cloud-starter-stream-redis)
[![License](https://img.shields.io/:license-apache-brightgreen.svg?style=flat-square)](http://www.apache.org/licenses/LICENSE-2.0.html)
[![CodeQL](https://github.com/guoshiqiufeng/spring-cloud-stream-redis/actions/workflows/github-code-scanning/codeql/badge.svg)](https://github.com/guoshiqiufeng/spring-cloud-stream-redis/actions/workflows/github-code-scanning/codeql)

阅读其他语言版本: [English](README.md)

### 介绍

基于Spring Cloud Stream 规范实现 Redis 消息 发送、接收, 正式版本 与 Spring Cloud Stream 保持一致

### 文档

https://guoshiqiufeng.github.io/spring-cloud-stream-redis/

### 开发框架

- Spring Cloud Stream 4
- Spring Boot 3

### 功能

- PUBLISH SUBSCRIBE 消息
- QUEUE 消息(BLPOP BRPOP LPUSH RPUSH)

> 注1: 两个功能模式不能混合使用,即 使用 PUBLISH SUBSCRIBE 模式 发送消息 时,不能使用 QUEUE 模式接收消息,反之亦然

> 注2: PUBLISH SUBSCRIBE 模式消息接收不到会丢失,QUEUE 模式不会

### 使用

#### 引入统一版本依赖,不用再使用时指定版本号

```xml



io.github.guoshiqiufeng.cloud
spring-cloud-stream-dependencies
0.4.0
import

```

#### 引入starter依赖

```xml

io.github.guoshiqiufeng.cloud
spring-cloud-starter-stream-redis

```

#### yml 配置

```yaml
spring:
cloud:
stream:
default-binder: redis
binders:
redis:
type: redis
redis:
binder:
configuration:
host: 127.0.0.1
port: 6379
password: 123456
database: 7
support-type: queue_channel
# bindings:
# send-in-0:
# consumer:
# destination-is-pattern: true
bindings:
out-0:
destination: test-topic
content-type: text/plain
group: push-producer-group
send-in-0:
destination: test-topic
content-type: text/plain
group: test-send-group
```

#### 消息发送

```java

@Autowired
private StreamBridge streamBridge;

@GetMapping("/send")
public String send() {
MessageVO messageVO = new MessageVO();
messageVO.setKey(UUID.randomUUID().toString());
messageVO.setMsg("hello ");
messageVO.setIds(Set.of("1", "2"));
messageVO.setCreateTime(LocalDateTime.now());
streamBridge.send("out-0", JSON.toJSONString(messageVO, JSONWriter.Feature.WriteClassName));
return "success";
}
```

### 消息接收

```java

@Slf4j
@Component("send")
public class MessageHandler implements Consumer> {

/**
* Performs this operation on the given argument.
*
* @param messageVOMessage the input argument
*/
@Override
public void accept(Message messageVOMessage) {
log.info("send Receive New Messages: {}", messageVOMessage.getPayload());
}
}
```

更多使用参考查看[文档](https://guoshiqiufeng.github.io/spring-cloud-stream-redis/zh/)