forked from guoshiqiufeng/spring-cloud-stream-redis
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5892c19
commit a4ffd3f
Showing
21 changed files
with
517 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,124 @@ | ||
## spring-cloud-stream-redis | ||
|
||
[](https://search.maven.org/search?q=g:io.github.guoshiqiufeng%20AND%20a:spring-cloud-stream-redis) | ||
[](https://search.maven.org/search?q=g:io.github.guoshiqiufeng%20AND%20a:spring-cloud-starter-stream-redis) | ||
[](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()); | ||
} | ||
} | ||
``` | ||
更多使用参考查看文档 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,123 @@ | ||
## spring-cloud-stream-redis | ||
|
||
[](https://search.maven.org/search?q=g:io.github.guoshiqiufeng%20AND%20a:loki) | ||
[](https://search.maven.org/search?q=g:io.github.guoshiqiufeng%20AND%20a:loki) | ||
[](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 |
15 changes: 15 additions & 0 deletions
15
...b/guoshiqiufeng/cloud/stream/binder/redis/common/RedisBinderEnvironmentPostProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
15 changes: 15 additions & 0 deletions
15
...uoshiqiufeng/cloud/stream/binder/redis/properties/RedisBinderConfigurationProperties.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
15 changes: 15 additions & 0 deletions
15
.../io/github/guoshiqiufeng/cloud/stream/binder/redis/properties/RedisBindingProperties.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
15 changes: 15 additions & 0 deletions
15
...io/github/guoshiqiufeng/cloud/stream/binder/redis/properties/RedisConsumerProperties.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
15 changes: 15 additions & 0 deletions
15
...ub/guoshiqiufeng/cloud/stream/binder/redis/properties/RedisExtendedBindingProperties.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
15 changes: 15 additions & 0 deletions
15
...io/github/guoshiqiufeng/cloud/stream/binder/redis/properties/RedisProducerProperties.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
||
/** | ||
|
15 changes: 15 additions & 0 deletions
15
...va/io/github/guoshiqiufeng/cloud/stream/binder/redis/properties/RedisTopicProperties.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
Oops, something went wrong.