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
- Host: GitHub
- URL: https://github.com/guoshiqiufeng/spring-cloud-stream-redis
- Owner: guoshiqiufeng
- License: apache-2.0
- Created: 2024-08-30T07:45:24.000Z (9 months ago)
- Default Branch: main
- Last Pushed: 2024-11-14T08:25:40.000Z (7 months ago)
- Last Synced: 2024-11-14T08:31:19.789Z (7 months ago)
- Topics: messaging, redis, spring-cloud-stream, spring-cloud-stream-redis
- Language: Java
- Homepage: https://guoshiqiufeng.github.io/spring-cloud-stream-redis
- Size: 210 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README-zh.md
- License: LICENSE
Awesome Lists containing this project
README
## spring-cloud-stream-redis
[](https://search.maven.org/search?q=g:io.github.guoshiqiufeng.cloud%20AND%20a:spring-cloud-starter-stream-redis)
[](http://www.apache.org/licenses/LICENSE-2.0.html)
[](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/)