Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
guoshiqiufeng committed Aug 30, 2024
1 parent 5892c19 commit a4ffd3f
Show file tree
Hide file tree
Showing 21 changed files with 517 additions and 41 deletions.
108 changes: 107 additions & 1 deletion README-zh.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,124 @@
## spring-cloud-stream-redis

[![Maven central](https://img.shields.io/maven-central/v/io.github.guoshiqiufeng/spring-cloud-stream-redis.svg?style=flat-square)](https://search.maven.org/search?q=g:io.github.guoshiqiufeng%20AND%20a: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%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)

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

### 介绍

基于Spring Cloud Stream 规范实现 Redis 消息 发送、接收

### 文档



### 开发框架

- Spring Cloud 2023.0.3
- Spring Boot 3.2.7

### 功能

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

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

#### 引入统一版本依赖,不用再使用时指定版本号
```xml
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.github.guoshiqiufeng.cloud</groupId>
<artifactId>spring-cloud-stream-dependencies</artifactId>
<version>0.1.0</version>
<type>import</type>
</dependency>
</dependencies>
</dependencyManagement>
```

#### 引入starter依赖

```xml
<dependency>
<groupId>io.github.guoshiqiufeng.cloud</groupId>
<artifactId>spring-cloud-starter-stream-redis</artifactId>
</dependency>
```

#### 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<Message<String>> {

/**
* Performs this operation on the given argument.
*
* @param messageVOMessage the input argument
*/
@Override
public void accept(Message<String> messageVOMessage) {
log.info("send Receive New Messages: {}", messageVOMessage.getPayload());
}
}
```
更多使用参考查看文档
107 changes: 106 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,123 @@
## spring-cloud-stream-redis

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

Read in other languages: [简体中文](README-zh.md)

### Introduction

Sending and Receiving Redis Messages Based on Spring Cloud Stream Specification

### Documentation

### Development Framework

- Spring Cloud 2023.0.3
- Spring Boot 3.2.7

### Features

- PUBLISH SUBSCRIBE message
- QUEUE message(BLPOP BRPOP LPUSH RPUSH)

> Tips 1: The two function modes cannot be mixed, i.e., if you send a message in PUBLISH SUBSCRIBE mode, you cannot receive a message in QUEUE mode, and vice versa.
> Tips 2: PUBLISH SUBSCRIBE mode messages will be lost if not received, QUEUE mode will not.
### Use


#### Introduces a uniform version dependency, so you don't have to specify a version number when you use it.
```xml
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.github.guoshiqiufeng.cloud</groupId>
<artifactId>spring-cloud-stream-dependencies</artifactId>
<version>0.1.0</version>
<type>import</type>
</dependency>
</dependencies>
</dependencyManagement>
```

#### Introducing starter dependencies

```xml
<dependency>
<groupId>io.github.guoshiqiufeng.cloud</groupId>
<artifactId>spring-cloud-starter-stream-redis</artifactId>
</dependency>
```

#### yml configuration

```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
```
#### Messaging
```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";
}
```

### Message reception

```java
@Slf4j
@Component("send")
public class MessageHandler implements Consumer<Message<String>> {

/**
* Performs this operation on the given argument.
*
* @param messageVOMessage the input argument
*/
@Override
public void accept(Message<String> messageVOMessage) {
log.info("send Receive New Messages: {}", messageVOMessage.getPayload());
}
}
```
For more usage references check the documentation
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
* Copyright (c) 2023-2024, fubluesky ([email protected])
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.github.guoshiqiufeng.cloud.stream.binder.redis.common;

import lombok.extern.slf4j.Slf4j;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
* Copyright (c) 2023-2024, fubluesky ([email protected])
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.github.guoshiqiufeng.cloud.stream.binder.redis.properties;

import lombok.Getter;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
* Copyright (c) 2023-2024, fubluesky ([email protected])
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.github.guoshiqiufeng.cloud.stream.binder.redis.properties;

import lombok.Data;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
* Copyright (c) 2023-2024, fubluesky ([email protected])
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.github.guoshiqiufeng.cloud.stream.binder.redis.properties;

import lombok.Getter;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
* Copyright (c) 2023-2024, fubluesky ([email protected])
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.github.guoshiqiufeng.cloud.stream.binder.redis.properties;

import org.springframework.boot.context.properties.ConfigurationProperties;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
* Copyright (c) 2023-2024, fubluesky ([email protected])
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.github.guoshiqiufeng.cloud.stream.binder.redis.properties;

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
* Copyright (c) 2023-2024, fubluesky ([email protected])
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.github.guoshiqiufeng.cloud.stream.binder.redis.properties;

import lombok.Data;
Expand Down
Loading

0 comments on commit a4ffd3f

Please sign in to comment.