diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..da20993 --- /dev/null +++ b/.gitignore @@ -0,0 +1,43 @@ +.gradle +build/ +!gradle/wrapper/gradle-wrapper.jar +!**/src/main/**/build/ +!**/src/test/**/build/ + +### IntelliJ IDEA ### +.idea +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..1da212d --- /dev/null +++ b/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + https://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "{}" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright (c) 2023-${year}, fubluesky (fubluesky@foxmail.com). + + 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 + + https://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. diff --git a/README-zh.md b/README-zh.md new file mode 100644 index 0000000..3836afb --- /dev/null +++ b/README-zh.md @@ -0,0 +1,18 @@ +## 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) +[![License](https://img.shields.io/:license-apache-brightgreen.svg?style=flat-square)](http://www.apache.org/licenses/LICENSE-2.0.html) + +阅读其他语言版本: [English](README.md) + +### 介绍 + +### 文档 + +### 开发框架 + +### 功能 + +### 使用 + + diff --git a/README.md b/README.md new file mode 100644 index 0000000..2f9a8fb --- /dev/null +++ b/README.md @@ -0,0 +1,18 @@ +## 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) +[![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 + +### Documentation + +### Development Framework + +### Features + +### Use + + diff --git a/binders/build.gradle b/binders/build.gradle new file mode 100644 index 0000000..e45f4d5 --- /dev/null +++ b/binders/build.gradle @@ -0,0 +1 @@ +tasks.matching { it.group == 'publishing' }.each { it.enabled = false } \ No newline at end of file diff --git a/binders/spring-cloud-starter-stream-redis/build.gradle b/binders/spring-cloud-starter-stream-redis/build.gradle new file mode 100644 index 0000000..bf7c52d --- /dev/null +++ b/binders/spring-cloud-starter-stream-redis/build.gradle @@ -0,0 +1,5 @@ +dependencies { + api project(":binders:spring-cloud-stream-binder-redis") + + api 'io.lettuce:lettuce-core' +} diff --git a/binders/spring-cloud-stream-binder-redis-core/build.gradle b/binders/spring-cloud-stream-binder-redis-core/build.gradle new file mode 100644 index 0000000..fc1e76b --- /dev/null +++ b/binders/spring-cloud-stream-binder-redis-core/build.gradle @@ -0,0 +1,14 @@ +dependencies { + + api "org.slf4j:slf4j-api" + api "org.springframework.cloud:spring-cloud-stream" + api "org.springframework.integration:spring-integration-redis" + api 'org.apache.commons:commons-pool2' + + implementation 'redis.clients:jedis' + + annotationProcessor "org.springframework.boot:spring-boot-starter-actuator" + annotationProcessor "org.springframework.boot:spring-boot-configuration-processor" + + testImplementation "org.springframework.boot:spring-boot-starter-test" +} diff --git a/binders/spring-cloud-stream-binder-redis-core/src/main/java/io/github/guoshiqiufeng/cloud/stream/binder/redis/common/RedisBinderEnvironmentPostProcessor.java b/binders/spring-cloud-stream-binder-redis-core/src/main/java/io/github/guoshiqiufeng/cloud/stream/binder/redis/common/RedisBinderEnvironmentPostProcessor.java new file mode 100644 index 0000000..17978c3 --- /dev/null +++ b/binders/spring-cloud-stream-binder-redis-core/src/main/java/io/github/guoshiqiufeng/cloud/stream/binder/redis/common/RedisBinderEnvironmentPostProcessor.java @@ -0,0 +1,63 @@ +package io.github.guoshiqiufeng.cloud.stream.binder.redis.common; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.env.EnvironmentPostProcessor; +import org.springframework.core.env.ConfigurableEnvironment; +import org.springframework.core.env.MapPropertySource; + +import java.util.HashMap; +import java.util.Map; + +/** + * An {@link EnvironmentPostProcessor} that sets some common configuration properties (log + * config etc.,) for Redis binder. + * + * @author yanghq + * @version 1.0 + * @since 2024/8/28 11:34 + */ +@Slf4j +public class RedisBinderEnvironmentPostProcessor implements EnvironmentPostProcessor { + + private static final String SPRING_REDIS = "spring.data.redis"; + + private static final String SPRING_REDIS_PRODUCER = SPRING_REDIS + ".producer"; + + private static final String SPRING_REDIS_CONSUMER = SPRING_REDIS + ".consumer"; + + private static final String SPRING_REDIS_PRODUCER_KEY_SERIALIZER = SPRING_REDIS_PRODUCER + + "." + "keySerializer"; + + private static final String SPRING_REDIS_PRODUCER_VALUE_SERIALIZER = SPRING_REDIS_PRODUCER + + "." + "valueSerializer"; + + private static final String SPRING_REDIS_CONSUMER_KEY_DESERIALIZER = SPRING_REDIS_CONSUMER + + "." + "keyDeserializer"; + + private static final String SPRING_REDIS_CONSUMER_VALUE_DESERIALIZER = SPRING_REDIS_CONSUMER + + "." + "valueDeserializer"; + + private static final String REDIS_BINDER_DEFAULT_PROPERTIES = "redisBinderConfigurationProperties"; + + + @Override + public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) { + log.error("postProcessEnvironment:{}", environment.getPropertySources()); + if (!environment.getPropertySources().contains(REDIS_BINDER_DEFAULT_PROPERTIES)) { + Map redisBinderDefaultProperties = new HashMap<>(); + redisBinderDefaultProperties.put("logging.level.io.github.guoshiqiufeng.stream", + "ERROR"); +// redisBinderDefaultProperties.put(SPRING_REDIS_PRODUCER_KEY_SERIALIZER, +// ByteArraySerializer.class.getName()); +// redisBinderDefaultProperties.put(SPRING_REDIS_PRODUCER_VALUE_SERIALIZER, +// ByteArraySerializer.class.getName()); +// redisBinderDefaultProperties.put(SPRING_REDIS_CONSUMER_KEY_DESERIALIZER, +// ByteArrayDeserializer.class.getName()); +// redisBinderDefaultProperties.put(SPRING_REDIS_CONSUMER_VALUE_DESERIALIZER, +// ByteArrayDeserializer.class.getName()); + environment.getPropertySources().addLast(new MapPropertySource( + REDIS_BINDER_DEFAULT_PROPERTIES, redisBinderDefaultProperties)); + } + } +} diff --git a/binders/spring-cloud-stream-binder-redis-core/src/main/java/io/github/guoshiqiufeng/cloud/stream/binder/redis/properties/RedisBinderConfigurationProperties.java b/binders/spring-cloud-stream-binder-redis-core/src/main/java/io/github/guoshiqiufeng/cloud/stream/binder/redis/properties/RedisBinderConfigurationProperties.java new file mode 100644 index 0000000..7f3f71a --- /dev/null +++ b/binders/spring-cloud-stream-binder-redis-core/src/main/java/io/github/guoshiqiufeng/cloud/stream/binder/redis/properties/RedisBinderConfigurationProperties.java @@ -0,0 +1,46 @@ +package io.github.guoshiqiufeng.cloud.stream.binder.redis.properties; + +import lombok.Getter; +import lombok.Setter; +import lombok.extern.slf4j.Slf4j; +import org.springframework.boot.autoconfigure.data.redis.RedisProperties; +import org.springframework.util.Assert; + +/** + * @author yanghq + * @version 1.0 + * @since 2024/8/28 09:58 + */ +@Slf4j +public class RedisBinderConfigurationProperties { + + private static final String DEFAULT_REDIS_CONNECTION_STRING = "localhost:6379"; + + @Getter + @Setter + private SupportType supportType = SupportType.PUBLISH_SUBSCRIBE_CHANNEL; + + @Getter + private final RedisProperties configuration; + + @Getter + @Setter + private String[] headers = new String[]{}; + + public RedisBinderConfigurationProperties(RedisProperties redisProperties) { + Assert.notNull(redisProperties, "'redisProperties' cannot be null"); + this.configuration = redisProperties; + } + + + public enum SupportType { + /** + * publish subscribe + */ + PUBLISH_SUBSCRIBE_CHANNEL, + /** + * list right pop + */ + QUEUE_CHANNEL + } +} diff --git a/binders/spring-cloud-stream-binder-redis-core/src/main/java/io/github/guoshiqiufeng/cloud/stream/binder/redis/properties/RedisBindingProperties.java b/binders/spring-cloud-stream-binder-redis-core/src/main/java/io/github/guoshiqiufeng/cloud/stream/binder/redis/properties/RedisBindingProperties.java new file mode 100644 index 0000000..a09aa4f --- /dev/null +++ b/binders/spring-cloud-stream-binder-redis-core/src/main/java/io/github/guoshiqiufeng/cloud/stream/binder/redis/properties/RedisBindingProperties.java @@ -0,0 +1,26 @@ +package io.github.guoshiqiufeng.cloud.stream.binder.redis.properties; + +import lombok.Data; +import org.springframework.cloud.stream.binder.BinderSpecificPropertiesProvider; + +/** + * Container object for Redis specific extended producer and consumer binding properties. + * + * @author yanghq + * @version 1.0 + * @since 2024/8/28 10:00 + */ +@Data +public class RedisBindingProperties implements BinderSpecificPropertiesProvider { + + /** + * Consumer specific binding properties. @see {@link RedisConsumerProperties}. + */ + private RedisConsumerProperties consumer = new RedisConsumerProperties(); + + /** + * Producer specific binding properties. @see {@link RedisProducerProperties}. + */ + private RedisProducerProperties producer = new RedisProducerProperties(); + +} diff --git a/binders/spring-cloud-stream-binder-redis-core/src/main/java/io/github/guoshiqiufeng/cloud/stream/binder/redis/properties/RedisConsumerProperties.java b/binders/spring-cloud-stream-binder-redis-core/src/main/java/io/github/guoshiqiufeng/cloud/stream/binder/redis/properties/RedisConsumerProperties.java new file mode 100644 index 0000000..cb2d9d8 --- /dev/null +++ b/binders/spring-cloud-stream-binder-redis-core/src/main/java/io/github/guoshiqiufeng/cloud/stream/binder/redis/properties/RedisConsumerProperties.java @@ -0,0 +1,38 @@ +package io.github.guoshiqiufeng.cloud.stream.binder.redis.properties; + +import lombok.Getter; +import lombok.Setter; + +import java.util.HashMap; +import java.util.Map; + +/** + * Extended consumer properties for Redis binder. + * + * @author yanghq + * @version 1.0 + * @since 2024/8/28 10:09 + */ +public class RedisConsumerProperties { + + /** + * When true, the destination is treated as a regular expression Pattern used to match topic names by the broker. + */ + @Getter + @Setter + private boolean destinationIsPattern; + + /** + * Map with a key/value pair containing generic redis consumer properties. + * In addition to having redis consumer properties, other configuration properties can be passed here. + */ + private Map configuration = new HashMap<>(); + + /** + * Various topic level properties. @see {@link RedisTopicProperties} for more details. + */ + @Getter + @Setter + private RedisTopicProperties topic = new RedisTopicProperties(); + +} diff --git a/binders/spring-cloud-stream-binder-redis-core/src/main/java/io/github/guoshiqiufeng/cloud/stream/binder/redis/properties/RedisExtendedBindingProperties.java b/binders/spring-cloud-stream-binder-redis-core/src/main/java/io/github/guoshiqiufeng/cloud/stream/binder/redis/properties/RedisExtendedBindingProperties.java new file mode 100644 index 0000000..0390e90 --- /dev/null +++ b/binders/spring-cloud-stream-binder-redis-core/src/main/java/io/github/guoshiqiufeng/cloud/stream/binder/redis/properties/RedisExtendedBindingProperties.java @@ -0,0 +1,36 @@ +package io.github.guoshiqiufeng.cloud.stream.binder.redis.properties; + +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.cloud.stream.binder.AbstractExtendedBindingProperties; +import org.springframework.cloud.stream.binder.BinderSpecificPropertiesProvider; + +import java.util.Map; + +/** + * Redis specific extended binding properties class that extends from + * {@link AbstractExtendedBindingProperties}. + * + * @author yanghq + * @version 1.0 + * @since 2024/8/28 10:30 + */ +@ConfigurationProperties("spring.cloud.stream.redis") +public class RedisExtendedBindingProperties extends + AbstractExtendedBindingProperties { + private static final String DEFAULTS_PREFIX = "spring.cloud.stream.redis.default"; + + @Override + public String getDefaultsPrefix() { + return DEFAULTS_PREFIX; + } + + @Override + public Map getBindings() { + return this.doGetBindings(); + } + + @Override + public Class getExtendedPropertiesEntryClass() { + return RedisBindingProperties.class; + } +} diff --git a/binders/spring-cloud-stream-binder-redis-core/src/main/java/io/github/guoshiqiufeng/cloud/stream/binder/redis/properties/RedisProducerProperties.java b/binders/spring-cloud-stream-binder-redis-core/src/main/java/io/github/guoshiqiufeng/cloud/stream/binder/redis/properties/RedisProducerProperties.java new file mode 100644 index 0000000..471a0c4 --- /dev/null +++ b/binders/spring-cloud-stream-binder-redis-core/src/main/java/io/github/guoshiqiufeng/cloud/stream/binder/redis/properties/RedisProducerProperties.java @@ -0,0 +1,11 @@ +package io.github.guoshiqiufeng.cloud.stream.binder.redis.properties; + +/** + * Extended producer properties for Redis binder. + * + * @author yanghq + * @version 1.0 + * @since 2024/8/28 10:09 + */ +public class RedisProducerProperties { +} diff --git a/binders/spring-cloud-stream-binder-redis-core/src/main/java/io/github/guoshiqiufeng/cloud/stream/binder/redis/properties/RedisTopicProperties.java b/binders/spring-cloud-stream-binder-redis-core/src/main/java/io/github/guoshiqiufeng/cloud/stream/binder/redis/properties/RedisTopicProperties.java new file mode 100644 index 0000000..bdd9823 --- /dev/null +++ b/binders/spring-cloud-stream-binder-redis-core/src/main/java/io/github/guoshiqiufeng/cloud/stream/binder/redis/properties/RedisTopicProperties.java @@ -0,0 +1,25 @@ +package io.github.guoshiqiufeng.cloud.stream.binder.redis.properties; + +import lombok.Data; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * Properties for configuring topics. + * + * @author yanghq + * @version 1.0 + * @since 2024/8/28 10:35 + */ +@Data +public class RedisTopicProperties { + + private Short replicationFactor; + + private Map> replicasAssignments = new HashMap<>(); + + private Map properties = new HashMap<>(); + +} diff --git a/binders/spring-cloud-stream-binder-redis-core/src/main/java/io/github/guoshiqiufeng/cloud/stream/binder/redis/provisioning/RedisTopicProvisioner.java b/binders/spring-cloud-stream-binder-redis-core/src/main/java/io/github/guoshiqiufeng/cloud/stream/binder/redis/provisioning/RedisTopicProvisioner.java new file mode 100644 index 0000000..2292006 --- /dev/null +++ b/binders/spring-cloud-stream-binder-redis-core/src/main/java/io/github/guoshiqiufeng/cloud/stream/binder/redis/provisioning/RedisTopicProvisioner.java @@ -0,0 +1,169 @@ +package io.github.guoshiqiufeng.cloud.stream.binder.redis.provisioning; + +import io.github.guoshiqiufeng.cloud.stream.binder.redis.properties.RedisBinderConfigurationProperties; +import io.github.guoshiqiufeng.cloud.stream.binder.redis.properties.RedisConsumerProperties; +import io.github.guoshiqiufeng.cloud.stream.binder.redis.properties.RedisProducerProperties; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.InitializingBean; +import org.springframework.cloud.stream.binder.ExtendedConsumerProperties; +import org.springframework.cloud.stream.binder.ExtendedProducerProperties; +import org.springframework.cloud.stream.provisioning.ConsumerDestination; +import org.springframework.cloud.stream.provisioning.ProducerDestination; +import org.springframework.cloud.stream.provisioning.ProvisioningException; +import org.springframework.cloud.stream.provisioning.ProvisioningProvider; +import org.springframework.retry.RetryOperations; +import org.springframework.retry.backoff.ExponentialBackOffPolicy; +import org.springframework.retry.policy.SimpleRetryPolicy; +import org.springframework.retry.support.RetryTemplate; +import org.springframework.util.StringUtils; + +/** + * Redis implementation for {@link ProvisioningProvider}. + * + * @author yanghq + * @version 1.0 + * @since 2024/8/28 13:56 + */ +@Slf4j +public class RedisTopicProvisioner implements + ProvisioningProvider, + ExtendedProducerProperties>, InitializingBean { + + private static final int DEFAULT_OPERATION_TIMEOUT = 30; + + private final RedisBinderConfigurationProperties configurationProperties; + + private final int operationTimeout = DEFAULT_OPERATION_TIMEOUT; + + private RetryOperations metadataRetryOperations; + + /** + * Create an instance. + * + * @param redisBinderConfigurationProperties the binder configuration properties. + */ + public RedisTopicProvisioner( + RedisBinderConfigurationProperties redisBinderConfigurationProperties) { + + this.configurationProperties = redisBinderConfigurationProperties; + + // If the application provides AdminConfig customizers + // and overrides properties, those take precedence. + // adminClientConfigCustomizers.forEach(customizer -> customizer.configure(this.adminClientProperties)); + } + + @Override + public void afterPropertiesSet() { + if (this.metadataRetryOperations == null) { + RetryTemplate retryTemplate = new RetryTemplate(); + + SimpleRetryPolicy simpleRetryPolicy = new SimpleRetryPolicy(); + simpleRetryPolicy.setMaxAttempts(10); + retryTemplate.setRetryPolicy(simpleRetryPolicy); + + ExponentialBackOffPolicy backOffPolicy = new ExponentialBackOffPolicy(); + backOffPolicy.setInitialInterval(100); + backOffPolicy.setMultiplier(2); + backOffPolicy.setMaxInterval(1000); + retryTemplate.setBackOffPolicy(backOffPolicy); + this.metadataRetryOperations = retryTemplate; + } + } + + @Override + public ProducerDestination provisionProducerDestination(String name, ExtendedProducerProperties properties) throws ProvisioningException { + if (log.isInfoEnabled()) { + log.info("Using redis topic for outbound: {}", name); + } + return new RedisProducerDestination(name, 0); + } + + @Override + public ConsumerDestination provisionConsumerDestination(String name, String group, ExtendedConsumerProperties properties) throws ProvisioningException { + if (!properties.isMultiplex()) { + return doProvisionConsumerDestination(name, group, properties); + } else { + String[] destinations = StringUtils.commaDelimitedListToStringArray(name); + for (String destination : destinations) { + doProvisionConsumerDestination(destination.trim(), group, properties); + } + return new RedisConsumerDestination(name); + } + } + + private ConsumerDestination doProvisionConsumerDestination(final String name, + final String group, + ExtendedConsumerProperties properties) { + final RedisConsumerDestination redisConsumerDestination = new RedisConsumerDestination(name); + if (properties.getExtension().isDestinationIsPattern()) { + return redisConsumerDestination; + } + return redisConsumerDestination; + } + + private static final class RedisProducerDestination implements ProducerDestination { + + private final String producerDestinationName; + + private final int partitions; + + RedisProducerDestination(String destinationName, Integer partitions) { + this.producerDestinationName = destinationName; + this.partitions = partitions; + } + + @Override + public String getName() { + return this.producerDestinationName; + } + + @Override + public String getNameForPartition(int partition) { + return this.producerDestinationName; + } + + @Override + public String toString() { + return "RedisProducerDestination{" + "producerDestinationName='" + + producerDestinationName + '\'' + ", partitions=" + partitions + '}'; + } + + } + + private static final class RedisConsumerDestination implements ConsumerDestination { + + private final String consumerDestinationName; + + private final int partitions; + + private final String dlqName; + + RedisConsumerDestination(String consumerDestinationName) { + this(consumerDestinationName, 0, null); + } + + RedisConsumerDestination(String consumerDestinationName, int partitions) { + this(consumerDestinationName, partitions, null); + } + + RedisConsumerDestination(String consumerDestinationName, Integer partitions, + String dlqName) { + this.consumerDestinationName = consumerDestinationName; + this.partitions = partitions; + this.dlqName = dlqName; + } + + @Override + public String getName() { + return this.consumerDestinationName; + } + + @Override + public String toString() { + return "RedisConsumerDestination{" + "consumerDestinationName='" + + consumerDestinationName + '\'' + ", partitions=" + partitions + + ", dlqName='" + dlqName + '\'' + '}'; + } + + } +} diff --git a/binders/spring-cloud-stream-binder-redis-core/src/main/java/io/github/guoshiqiufeng/cloud/stream/binder/redis/utils/RedisConnectionFactoryUtil.java b/binders/spring-cloud-stream-binder-redis-core/src/main/java/io/github/guoshiqiufeng/cloud/stream/binder/redis/utils/RedisConnectionFactoryUtil.java new file mode 100644 index 0000000..8da255e --- /dev/null +++ b/binders/spring-cloud-stream-binder-redis-core/src/main/java/io/github/guoshiqiufeng/cloud/stream/binder/redis/utils/RedisConnectionFactoryUtil.java @@ -0,0 +1,147 @@ +package io.github.guoshiqiufeng.cloud.stream.binder.redis.utils; + +import lombok.experimental.UtilityClass; +import org.apache.commons.pool2.impl.GenericObjectPoolConfig; +import org.springframework.beans.BeanUtils; +import org.springframework.boot.autoconfigure.data.redis.RedisProperties; +import org.springframework.data.redis.connection.*; +import org.springframework.data.redis.connection.jedis.JedisClientConfiguration; +import org.springframework.data.redis.connection.jedis.JedisConnectionFactory; +import org.springframework.data.redis.connection.lettuce.LettuceClientConfiguration; +import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; + +import java.util.List; +import java.util.Optional; + +/** + * @author yanghq + * @version 1.0 + * @since 2024/8/28 15:52 + */ +@UtilityClass +public class RedisConnectionFactoryUtil { + + public RedisConnectionFactory getRedisConnectionFactory(RedisProperties redisProperties) { + RedisProperties.ClientType clientType = redisProperties.getClientType(); + + if (clientType == RedisProperties.ClientType.JEDIS) { + // 使用 Jedis 作为 Redis 客户端 + JedisConnectionFactory jedisConnectionFactory = configureJedisClient(redisProperties); + jedisConnectionFactory.start(); + return jedisConnectionFactory; + } else { + // 使用 Lettuce 作为 Redis 客户端 + LettuceConnectionFactory lettuceConnectionFactory = configureLettuceClient(redisProperties); + lettuceConnectionFactory.start(); + return lettuceConnectionFactory; + } + } + + + private JedisConnectionFactory configureJedisClient(RedisProperties redisProperties) { + GenericObjectPoolConfig poolConfig = createPoolConfig(redisProperties); + JedisClientConfiguration clientConfiguration = JedisClientConfiguration.builder() + .usePooling() + .poolConfig(poolConfig) + .build(); + + return Optional.ofNullable(getSentinelConfig(redisProperties)) + .map(sentinelConfig -> new JedisConnectionFactory(sentinelConfig, clientConfiguration)) + .orElseGet(() -> createJedisConnectionFactoryWithFallback(redisProperties, clientConfiguration)); + } + + private GenericObjectPoolConfig createPoolConfig(RedisProperties redisProperties) { + GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig<>(); + BeanUtils.copyProperties(redisProperties.getJedis().getPool(), poolConfig); + return poolConfig; + } + + private JedisConnectionFactory createJedisConnectionFactoryWithFallback(RedisProperties redisProperties, JedisClientConfiguration clientConfiguration) { + RedisClusterConfiguration clusterConfig = getClusterConfiguration(redisProperties); + if (clusterConfig != null) { + return new JedisConnectionFactory(clusterConfig, clientConfiguration); + } else { + RedisStandaloneConfiguration standaloneConfig = getStandaloneConfig(redisProperties); + return new JedisConnectionFactory(standaloneConfig, clientConfiguration); + } + } + + + private LettuceConnectionFactory configureLettuceClient(RedisProperties redisProperties) { + LettuceClientConfiguration clientConfiguration = LettuceClientConfiguration.builder() + .build(); + + return Optional.ofNullable(getSentinelConfig(redisProperties)) + .map(sentinelConfig -> new LettuceConnectionFactory(sentinelConfig, clientConfiguration)) + .orElseGet(() -> createLettuceConnectionFactoryWithFallback(redisProperties, clientConfiguration)); + } + + private LettuceConnectionFactory createLettuceConnectionFactoryWithFallback(RedisProperties redisProperties, LettuceClientConfiguration clientConfiguration) { + RedisClusterConfiguration clusterConfig = getClusterConfiguration(redisProperties); + if (clusterConfig != null) { + return new LettuceConnectionFactory(clusterConfig, clientConfiguration); + } else { + RedisStandaloneConfiguration standaloneConfig = getStandaloneConfig(redisProperties); + return new LettuceConnectionFactory(standaloneConfig, clientConfiguration); + } + } + + private static RedisSentinelConfiguration getSentinelConfig(RedisProperties redisProperties) { + if (redisProperties.getSentinel() != null) { + RedisSentinelConfiguration config = new RedisSentinelConfiguration(); + config.master(redisProperties.getSentinel().getMaster()); + config.setSentinels(createSentinels(redisProperties.getSentinel())); + config.setUsername(redisProperties.getUsername()); + String password = redisProperties.getPassword(); + if (password != null) { + config.setPassword(RedisPassword.of(password)); + } + config.setSentinelUsername(redisProperties.getSentinel().getUsername()); + String sentinelPassword = redisProperties.getSentinel().getPassword(); + if (sentinelPassword != null) { + config.setSentinelPassword(RedisPassword.of(sentinelPassword)); + } + config.setDatabase(redisProperties.getDatabase()); + return config; + } + return null; + } + + private RedisClusterConfiguration getClusterConfiguration(RedisProperties redisProperties) { + RedisProperties.Cluster clusterProperties = redisProperties.getCluster(); + if (redisProperties.getCluster() != null) { + RedisClusterConfiguration config = new RedisClusterConfiguration(); + config.setClusterNodes(getNodes(redisProperties.getCluster())); + if (clusterProperties != null && clusterProperties.getMaxRedirects() != null) { + config.setMaxRedirects(clusterProperties.getMaxRedirects()); + } + config.setUsername(redisProperties.getUsername()); + String password = redisProperties.getPassword(); + if (password != null) { + config.setPassword(RedisPassword.of(password)); + } + return config; + } + return null; + } + + private List getNodes(RedisProperties.Cluster cluster) { + return cluster.getNodes().stream().map(RedisNode::fromString).toList(); + } + + + private RedisStandaloneConfiguration getStandaloneConfig(RedisProperties redisProperties) { + RedisStandaloneConfiguration config = new RedisStandaloneConfiguration(); + config.setHostName(redisProperties.getHost()); + config.setPort(redisProperties.getPort()); + config.setUsername(redisProperties.getUsername()); + config.setPassword(RedisPassword.of(redisProperties.getPassword())); + config.setDatabase(redisProperties.getDatabase()); + return config; + } + + private List createSentinels(RedisProperties.Sentinel sentinel) { + return sentinel.getNodes().stream().map(RedisNode::fromString).toList(); + } + +} diff --git a/binders/spring-cloud-stream-binder-redis-core/src/test/java/io/github/guoshiqiufeng/cloud/stream/binder/redis/properties/RedisBinderConfigurationPropertiesTest.java b/binders/spring-cloud-stream-binder-redis-core/src/test/java/io/github/guoshiqiufeng/cloud/stream/binder/redis/properties/RedisBinderConfigurationPropertiesTest.java new file mode 100644 index 0000000..4e01a1d --- /dev/null +++ b/binders/spring-cloud-stream-binder-redis-core/src/test/java/io/github/guoshiqiufeng/cloud/stream/binder/redis/properties/RedisBinderConfigurationPropertiesTest.java @@ -0,0 +1,9 @@ +package io.github.guoshiqiufeng.cloud.stream.binder.redis.properties; + +/** + * @author yanghq + * @version 1.0 + * @since 2024/8/28 10:41 + */ +public class RedisBinderConfigurationPropertiesTest { +} diff --git a/binders/spring-cloud-stream-binder-redis/build.gradle b/binders/spring-cloud-stream-binder-redis/build.gradle new file mode 100644 index 0000000..e5cfcdb --- /dev/null +++ b/binders/spring-cloud-stream-binder-redis/build.gradle @@ -0,0 +1,11 @@ +dependencies { + api project(":binders:spring-cloud-stream-binder-redis-core") + + // implementation "org.springframework.cloud:spring-cloud-stream" + + annotationProcessor "org.springframework.boot:spring-boot-starter-actuator" + annotationProcessor "org.springframework.boot:spring-boot-configuration-processor" + annotationProcessor "org.springframework.boot:spring-boot-autoconfigure" + + testImplementation "org.springframework.boot:spring-boot-starter-test" +} diff --git a/binders/spring-cloud-stream-binder-redis/src/main/java/io/github/guoshiqiufeng/cloud/stream/binder/redis/RedisMessageChannelBinder.java b/binders/spring-cloud-stream-binder-redis/src/main/java/io/github/guoshiqiufeng/cloud/stream/binder/redis/RedisMessageChannelBinder.java new file mode 100644 index 0000000..44a772f --- /dev/null +++ b/binders/spring-cloud-stream-binder-redis/src/main/java/io/github/guoshiqiufeng/cloud/stream/binder/redis/RedisMessageChannelBinder.java @@ -0,0 +1,181 @@ +package io.github.guoshiqiufeng.cloud.stream.binder.redis; + +import io.github.guoshiqiufeng.cloud.stream.binder.redis.properties.RedisBinderConfigurationProperties; +import io.github.guoshiqiufeng.cloud.stream.binder.redis.properties.RedisConsumerProperties; +import io.github.guoshiqiufeng.cloud.stream.binder.redis.properties.RedisExtendedBindingProperties; +import io.github.guoshiqiufeng.cloud.stream.binder.redis.properties.RedisProducerProperties; +import io.github.guoshiqiufeng.cloud.stream.binder.redis.provisioning.RedisTopicProvisioner; +import io.github.guoshiqiufeng.cloud.stream.binder.redis.utils.RedisConnectionFactoryUtil; +import lombok.Setter; +import org.springframework.beans.factory.BeanFactory; +import org.springframework.cloud.stream.binder.*; +import org.springframework.cloud.stream.config.ListenerContainerCustomizer; +import org.springframework.cloud.stream.config.MessageSourceCustomizer; +import org.springframework.cloud.stream.provisioning.ConsumerDestination; +import org.springframework.cloud.stream.provisioning.ProducerDestination; +import org.springframework.context.support.AbstractApplicationContext; +import org.springframework.data.redis.connection.RedisConnectionFactory; +import org.springframework.integration.core.MessageProducer; +import org.springframework.integration.redis.inbound.RedisInboundChannelAdapter; +import org.springframework.integration.redis.inbound.RedisQueueMessageDrivenEndpoint; +import org.springframework.integration.redis.outbound.RedisPublishingMessageHandler; +import org.springframework.integration.redis.outbound.RedisQueueOutboundChannelAdapter; +import org.springframework.messaging.MessageChannel; +import org.springframework.messaging.MessageHandler; +import org.springframework.util.Assert; +import org.springframework.util.ObjectUtils; +import org.springframework.util.StringUtils; + +import java.util.Arrays; +import java.util.UUID; + +/** + * @author yanghq + * @version 1.0 + * @since 2024/8/28 13:53 + */ +public class RedisMessageChannelBinder extends + AbstractMessageChannelBinder, + ExtendedProducerProperties, RedisTopicProvisioner> + implements + ExtendedPropertiesBinder { + + private final RedisBinderConfigurationProperties configurationProperties; + + @Setter + private RedisExtendedBindingProperties extendedBindingProperties = new RedisExtendedBindingProperties(); + + public RedisMessageChannelBinder(RedisBinderConfigurationProperties configurationProperties, + RedisTopicProvisioner provisioningProvider, + ListenerContainerCustomizer containerCustomizer, + MessageSourceCustomizer sourceCustomizer + ) { + super(headersToMap(configurationProperties), provisioningProvider, + containerCustomizer, sourceCustomizer); + this.configurationProperties = configurationProperties; + } + + private static String[] headersToMap( + RedisBinderConfigurationProperties configurationProperties) { + String[] headersToMap; + if (ObjectUtils.isEmpty(configurationProperties.getHeaders())) { + headersToMap = BinderHeaders.STANDARD_HEADERS; + } else { + String[] combinedHeadersToMap = Arrays.copyOfRange( + BinderHeaders.STANDARD_HEADERS, 0, + BinderHeaders.STANDARD_HEADERS.length + + configurationProperties.getHeaders().length); + System.arraycopy(configurationProperties.getHeaders(), 0, + combinedHeadersToMap, BinderHeaders.STANDARD_HEADERS.length, + configurationProperties.getHeaders().length); + headersToMap = combinedHeadersToMap; + } + return headersToMap; + } + + @Override + protected MessageHandler createProducerMessageHandler(ProducerDestination destination, + ExtendedProducerProperties producerProperties, + MessageChannel errorChannel) throws Exception { + throw new IllegalStateException( + "The abstract binder should not call this method"); + } + + @Override + protected MessageHandler createProducerMessageHandler(ProducerDestination destination, ExtendedProducerProperties producerProperties, MessageChannel channel, MessageChannel errorChannel) throws Exception { + + RedisConnectionFactory connectionFactory = RedisConnectionFactoryUtil.getRedisConnectionFactory( + configurationProperties.getConfiguration()); + + AbstractApplicationContext applicationContext = getApplicationContext(); + BeanFactory beanFactory = applicationContext.getBeanFactory(); + + RedisBinderConfigurationProperties.SupportType supportType = configurationProperties.getSupportType(); + if (supportType == null || supportType.equals(RedisBinderConfigurationProperties.SupportType.PUBLISH_SUBSCRIBE_CHANNEL)) { + RedisPublishingMessageHandler handler = new RedisPublishingMessageHandler(connectionFactory); + handler.setTopic(destination.getName()); + handler.setApplicationContext(applicationContext); + handler.setBeanFactory(beanFactory); + return handler; + } else { + RedisQueueOutboundChannelAdapter handler = new RedisQueueOutboundChannelAdapter(destination.getName(), connectionFactory); + // handler.set + handler.setApplicationContext(applicationContext); + handler.setBeanFactory(beanFactory); + return handler; + } + } + + @Override + protected MessageProducer createConsumerEndpoint(ConsumerDestination destination, String group, + ExtendedConsumerProperties extendedConsumerProperties) { + boolean anonymous = !StringUtils.hasText(group); + + String consumerGroup = anonymous ? "anonymous." + UUID.randomUUID() : group; + + int partitionCount = extendedConsumerProperties.getInstanceCount() + * extendedConsumerProperties.getConcurrency(); + + boolean usingPatterns = extendedConsumerProperties.getExtension().isDestinationIsPattern(); + Assert.isTrue(!usingPatterns || !extendedConsumerProperties.isMultiplex(), + "Cannot use a pattern with multiplexed destinations; " + + "use the regex pattern to specify multiple topics instead"); + + AbstractApplicationContext applicationContext = getApplicationContext(); + + + RedisConnectionFactory connectionFactory = RedisConnectionFactoryUtil.getRedisConnectionFactory( + configurationProperties.getConfiguration()); + + RedisBinderConfigurationProperties.SupportType supportType = configurationProperties.getSupportType(); + if (supportType == null || supportType.equals(RedisBinderConfigurationProperties.SupportType.PUBLISH_SUBSCRIBE_CHANNEL)) { + RedisInboundChannelAdapter redisInboundChannelAdapter = new RedisInboundChannelAdapter(connectionFactory); + if (usingPatterns) { + redisInboundChannelAdapter.setTopicPatterns(destination.getName()); + } else { + redisInboundChannelAdapter.setTopics(destination.getName()); + } + redisInboundChannelAdapter.setBeanName(extendedConsumerProperties.getBindingName()); + redisInboundChannelAdapter.setBeanFactory(getBeanFactory()); + redisInboundChannelAdapter.setApplicationContext(applicationContext); + return redisInboundChannelAdapter; + } else { + Assert.isTrue(!usingPatterns, + "Cannot use a pattern with queued channel; " + + "Please use the PUBLISH_SUBSCRIBE_CHANNEL support type, or turn off the regex pattern."); + + RedisQueueMessageDrivenEndpoint redisQueueMessageDrivenEndpoint = new RedisQueueMessageDrivenEndpoint(destination.getName(), connectionFactory); + redisQueueMessageDrivenEndpoint.setBeanName(extendedConsumerProperties.getBindingName()); + redisQueueMessageDrivenEndpoint.setBeanFactory(getBeanFactory()); + redisQueueMessageDrivenEndpoint.setApplicationContext(applicationContext); + return redisQueueMessageDrivenEndpoint; + } + // ErrorInfrastructure errorInfrastructure = registerErrorInfrastructure(destination, + // consumerGroup, extendedConsumerProperties); + + // ListenerContainerCustomizer customizer = getContainerCustomizer(); + + // return redisMessageDrivenChannelAdapter; + } + + @Override + public RedisConsumerProperties getExtendedConsumerProperties(String channelName) { + return this.extendedBindingProperties.getExtendedConsumerProperties(channelName); + } + + @Override + public RedisProducerProperties getExtendedProducerProperties(String channelName) { + return this.extendedBindingProperties.getExtendedProducerProperties(channelName); + } + + @Override + public String getDefaultsPrefix() { + return this.extendedBindingProperties.getDefaultsPrefix(); + } + + @Override + public Class getExtendedPropertiesEntryClass() { + return this.extendedBindingProperties.getExtendedPropertiesEntryClass(); + } + +} diff --git a/binders/spring-cloud-stream-binder-redis/src/main/java/io/github/guoshiqiufeng/cloud/stream/binder/redis/aot/RedisBinderRuntimeHints.java b/binders/spring-cloud-stream-binder-redis/src/main/java/io/github/guoshiqiufeng/cloud/stream/binder/redis/aot/RedisBinderRuntimeHints.java new file mode 100644 index 0000000..3c3d685 --- /dev/null +++ b/binders/spring-cloud-stream-binder-redis/src/main/java/io/github/guoshiqiufeng/cloud/stream/binder/redis/aot/RedisBinderRuntimeHints.java @@ -0,0 +1,28 @@ +//package io.github.guoshiqiufeng.stream.binder.redis.aot; +// +//import io.github.guoshiqiufeng.stream.binder.redis.properties.RedisBindingProperties; +//import io.github.guoshiqiufeng.stream.binder.redis.properties.RedisConsumerProperties; +//import io.github.guoshiqiufeng.stream.binder.redis.properties.RedisExtendedBindingProperties; +//import io.github.guoshiqiufeng.stream.binder.redis.properties.RedisProducerProperties; +// +//import java.util.stream.Stream; +// +///** +// * @author yanghq +// * @version 1.0 +// * @since 2024/8/28 10:52 +// */ +//public class RedisBinderRuntimeHints implements RuntimeHintsRegistrar { +// +// @Override +// public void registerHints(RuntimeHints hints, @Nullable ClassLoader classLoader) { +// ReflectionHints reflectionHints = hints.reflection(); +// Stream.of( +// RedisConsumerProperties.class, +// RedisProducerProperties.class, +// RedisExtendedBindingProperties.class, +// RedisBindingProperties.class) +// .forEach(type -> reflectionHints.registerType(type, +// builder -> builder.withMembers(MemberCategory.INVOKE_DECLARED_METHODS))); +// } +//} diff --git a/binders/spring-cloud-stream-binder-redis/src/main/java/io/github/guoshiqiufeng/cloud/stream/binder/redis/config/ExtendedBindingHandlerMappingsProviderConfiguration.java b/binders/spring-cloud-stream-binder-redis/src/main/java/io/github/guoshiqiufeng/cloud/stream/binder/redis/config/ExtendedBindingHandlerMappingsProviderConfiguration.java new file mode 100644 index 0000000..957b88c --- /dev/null +++ b/binders/spring-cloud-stream-binder-redis/src/main/java/io/github/guoshiqiufeng/cloud/stream/binder/redis/config/ExtendedBindingHandlerMappingsProviderConfiguration.java @@ -0,0 +1,31 @@ +package io.github.guoshiqiufeng.cloud.stream.binder.redis.config; + +import org.springframework.boot.context.properties.source.ConfigurationPropertyName; +import org.springframework.cloud.stream.config.BindingHandlerAdvise; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import java.util.HashMap; +import java.util.Map; + +/** + * Configuration for extended binding metadata. + * + * @author yanghq + * @version 1.0 + * @since 2024/8/28 11:39 + */ +@Configuration(proxyBeanMethods = false) +public class ExtendedBindingHandlerMappingsProviderConfiguration { + + @Bean + public BindingHandlerAdvise.MappingsProvider redisExtendedPropertiesDefaultMappingsProvider() { + return () -> { + Map mappings = new HashMap<>(); + mappings.put( + ConfigurationPropertyName.of("spring.cloud.stream.redis.bindings"), + ConfigurationPropertyName.of("spring.cloud.stream.redis.default")); + return mappings; + }; + } +} diff --git a/binders/spring-cloud-stream-binder-redis/src/main/java/io/github/guoshiqiufeng/cloud/stream/binder/redis/config/RedisBinderConfiguration.java b/binders/spring-cloud-stream-binder-redis/src/main/java/io/github/guoshiqiufeng/cloud/stream/binder/redis/config/RedisBinderConfiguration.java new file mode 100644 index 0000000..278202f --- /dev/null +++ b/binders/spring-cloud-stream-binder-redis/src/main/java/io/github/guoshiqiufeng/cloud/stream/binder/redis/config/RedisBinderConfiguration.java @@ -0,0 +1,70 @@ +package io.github.guoshiqiufeng.cloud.stream.binder.redis.config; + +import io.github.guoshiqiufeng.cloud.stream.binder.redis.RedisMessageChannelBinder; +import io.github.guoshiqiufeng.cloud.stream.binder.redis.properties.RedisBinderConfigurationProperties; +import io.github.guoshiqiufeng.cloud.stream.binder.redis.properties.RedisExtendedBindingProperties; +import io.github.guoshiqiufeng.cloud.stream.binder.redis.provisioning.RedisTopicProvisioner; +import jakarta.annotation.Nullable; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.boot.autoconfigure.data.redis.RedisProperties; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.cloud.stream.binder.Binder; +import org.springframework.cloud.stream.config.ConsumerEndpointCustomizer; +import org.springframework.cloud.stream.config.ListenerContainerCustomizer; +import org.springframework.cloud.stream.config.MessageSourceCustomizer; +import org.springframework.cloud.stream.config.ProducerMessageHandlerCustomizer; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.data.redis.listener.RedisMessageListenerContainer; +import org.springframework.integration.redis.inbound.RedisQueueMessageDrivenEndpoint; +import org.springframework.integration.redis.inbound.RedisStoreMessageSource; + +/** + * @author yanghq + * @version 1.0 + * @since 2024/8/28 10:55 + */ +@Configuration(proxyBeanMethods = false) +@ConditionalOnMissingBean(Binder.class) +// @Import({RedisBinderHealthIndicatorConfiguration.class}) +@EnableConfigurationProperties({RedisProperties.class, RedisExtendedBindingProperties.class}) +public class RedisBinderConfiguration { + + @Bean + @ConfigurationProperties(prefix = "spring.cloud.stream.redis.binder") + RedisBinderConfigurationProperties configurationProperties( + RedisProperties redisProperties) { + return new RedisBinderConfigurationProperties(redisProperties); + } + + + @Bean + RedisTopicProvisioner provisioningProvider(RedisBinderConfigurationProperties configurationProperties) { + return new RedisTopicProvisioner(configurationProperties); + } + + @SuppressWarnings({"rawtypes", "unchecked"}) + @Bean + RedisMessageChannelBinder redisMessageChannelBinder( + RedisBinderConfigurationProperties configurationProperties, + RedisTopicProvisioner provisioningProvider, + @Nullable ListenerContainerCustomizer listenerContainerCustomizer, + @Nullable MessageSourceCustomizer sourceCustomizer, + @Nullable ProducerMessageHandlerCustomizer messageHandlerCustomizer, + @Nullable ConsumerEndpointCustomizer consumerCustomizer, + RedisExtendedBindingProperties redisExtendedBindingProperties + ) { + + RedisMessageChannelBinder redisMessageChannelBinder = new RedisMessageChannelBinder( + configurationProperties, provisioningProvider, + listenerContainerCustomizer, sourceCustomizer); + redisMessageChannelBinder + .setExtendedBindingProperties(redisExtendedBindingProperties); + redisMessageChannelBinder.setProducerMessageHandlerCustomizer(messageHandlerCustomizer); + redisMessageChannelBinder.setConsumerEndpointCustomizer(consumerCustomizer); + return redisMessageChannelBinder; + } + + +} diff --git a/binders/spring-cloud-stream-binder-redis/src/main/resources/META-INF/spring.binders b/binders/spring-cloud-stream-binder-redis/src/main/resources/META-INF/spring.binders new file mode 100644 index 0000000..110f98a --- /dev/null +++ b/binders/spring-cloud-stream-binder-redis/src/main/resources/META-INF/spring.binders @@ -0,0 +1,2 @@ +redis:\ +io.github.guoshiqiufeng.cloud.stream.binder.redis.config.RedisBinderConfiguration diff --git a/binders/spring-cloud-stream-binder-redis/src/main/resources/META-INF/spring.factories b/binders/spring-cloud-stream-binder-redis/src/main/resources/META-INF/spring.factories new file mode 100644 index 0000000..a9c7418 --- /dev/null +++ b/binders/spring-cloud-stream-binder-redis/src/main/resources/META-INF/spring.factories @@ -0,0 +1,2 @@ +org.springframework.boot.env.EnvironmentPostProcessor:\ +io.github.guoshiqiufeng.cloud.stream.binder.redis.common.RedisBinderEnvironmentPostProcessor diff --git a/binders/spring-cloud-stream-binder-redis/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/binders/spring-cloud-stream-binder-redis/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports new file mode 100644 index 0000000..6c0e864 --- /dev/null +++ b/binders/spring-cloud-stream-binder-redis/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -0,0 +1 @@ +io.github.guoshiqiufeng.cloud.stream.binder.redis.config.ExtendedBindingHandlerMappingsProviderConfiguration diff --git a/bom/build.gradle b/bom/build.gradle new file mode 100644 index 0000000..3ed6d8f --- /dev/null +++ b/bom/build.gradle @@ -0,0 +1 @@ +tasks.matching { it.group == 'publishing' }.each { it.enabled = false } diff --git a/bom/spring-cloud-starter-parent/build.gradle b/bom/spring-cloud-starter-parent/build.gradle new file mode 100644 index 0000000..372accb --- /dev/null +++ b/bom/spring-cloud-starter-parent/build.gradle @@ -0,0 +1,20 @@ +buildscript { + repositories { + maven { url "https://plugins.gradle.org/m2/" } + maven { url "https://repo.spring.io/plugins-release" } + } + dependencies { + classpath "io.spring.gradle:dependency-management-plugin:1.1.3" + } +} + +apply plugin: "io.spring.dependency-management" +apply from: '../../ext.gradle' + +description = "Specifies Boot version for the releaser" + +dependencyManagement { + imports { + mavenBom "org.springframework.boot:spring-boot-dependencies:${springBoot3Version}" + } +} diff --git a/bom/spring-cloud-stream-dependencies/build.gradle b/bom/spring-cloud-stream-dependencies/build.gradle new file mode 100644 index 0000000..af42174 --- /dev/null +++ b/bom/spring-cloud-stream-dependencies/build.gradle @@ -0,0 +1,21 @@ +buildscript { + repositories { + maven { url "https://plugins.gradle.org/m2/" } + maven { url "https://repo.spring.io/plugins-release" } + } + dependencies { + classpath "io.spring.gradle:dependency-management-plugin:1.1.3" + } +} + +apply plugin: "io.spring.dependency-management" + +description = "Spring Cloud Stream Dependencies" + +dependencyManagement { + dependencies { + dependency "io.github.guoshiqiufeng:spring-cloud-stream-binder-redis-core:${APP_VERSION}" + dependency "io.github.guoshiqiufeng:spring-cloud-stream-binder-redis:${APP_VERSION}" + dependency "io.github.guoshiqiufeng:spring-cloud-starter-stream-redis:${APP_VERSION}" + } +} diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..1059aaf --- /dev/null +++ b/build.gradle @@ -0,0 +1,215 @@ +import java.time.LocalDateTime + +allprojects { + group APP_GROUP + version APP_VERSION +} + +apply from: 'ext.gradle' + +description = "spring cloud stream redis" + +subprojects { + apply plugin: 'java-library' + apply plugin: 'signing' + apply plugin: 'maven-publish' + apply plugin: "io.freefair.lombok" + apply plugin: 'com.github.hierynomus.license' + apply plugin: "io.spring.dependency-management" + + sourceCompatibility = "${javaVersion}" + targetCompatibility = "${javaVersion}" + + lombok { + version = "1.18.30" + } + + compileJava { + options.release = 17 + } + + repositories { + mavenLocal() + maven { url "https://maven.aliyun.com/repository/public" } + maven { url "https://oss.sonatype.org/content/repositories/snapshots/" } + mavenCentral() + } + + def onlyPom = project.name == "spring-cloud-starter-parent" || project.name == "spring-cloud-stream-dependencies" + + if (!onlyPom) { + dependencyManagement { + imports { + mavenBom "org.springframework.boot:spring-boot-dependencies:${springBoot3Version}" + mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}" + } + dependencies { + + } + } + } + + tasks.withType(JavaCompile) { + options.encoding = 'UTF-8' + options.warnings = false + options.deprecation = true + options.compilerArgs += ["-parameters"] + } + + tasks.withType(GenerateModuleMetadata) { + enabled = false + } + + jar { + into("META-INF/") { + from rootProject.file("LICENSE") + } + into("META-INF/maven/$project.group/$project.name") { + from { generatePomFileForMavenJavaPublication } + rename ".*", "pom.xml" + } + afterEvaluate { + manifest { + attributes 'Implementation-Title': archiveBaseName + attributes 'Implementation-Version': archiveVersion + attributes 'Built-Gradle': gradle.gradleVersion + attributes 'Bundle-DocURL': 'https://guoshiqiufeng.github.io/spring-cloud-stream-redis' + attributes 'Build-OS': System.getProperty("os.name") + attributes 'Built-By': System.getProperty("user.name") + attributes 'Build-Jdk': System.getProperty("java.version") + attributes 'Build-Timestamp': LocalDateTime.now().format("yyyy-MM-dd HH:mm:ss") + attributes 'Automatic-Module-Name': "${project.group}.${project.name.replaceAll("-", ".")}" + } + } + } + + license { + encoding = "UTF-8" + header = rootProject.file("header.txt") + includes(["**/*.java", "**/*.kt"]) + mapping { + java = "SLASHSTAR_STYLE" + kt = "SLASHSTAR_STYLE" + } + ignoreFailures = true + ext.year = Calendar.getInstance().get(Calendar.YEAR) + } + + task sourcesJar(type: Jar) { + archiveClassifier = 'sources' + from sourceSets.main.allSource + } + + javadoc { + // Check for syntax during linting. 'none' doesn't seem to work in suppressing + // all linting warnings all the time (see/link references most notably). + options.addStringOption("Xdoclint:syntax", "-quiet") + + // Suppress warnings due to cross-module @see and @link references. + // Note that global 'api' task does display all warnings, and + // checks for 'reference' on top of 'syntax'. + logging.captureStandardError LogLevel.INFO + logging.captureStandardOutput LogLevel.INFO // suppress "## warnings" message + + afterEvaluate { + configure(options) { + encoding "UTF-8" + charSet 'UTF-8' + author true + version true + failOnError false + links "https://docs.oracle.com/javase/8/docs/api" + } + } + } + + test { + dependsOn("cleanTest", "generatePomFileForMavenJavaPublication") + useJUnitPlatform() + } + + task javadocJar(type: Jar) { + archiveClassifier = 'javadoc' + from javadoc + } + + tasks.whenTaskAdded { task -> + if (task.name.contains('signMavenJavaPublication') && project.hasProperty('signing.secretKeyRingFile')) { + task.enabled = new File(project.property('signing.secretKeyRingFile') as String).isFile() + } + } + + publishing { + repositories { + maven { + def releasesRepoUrl = "https://oss.sonatype.org/service/local/staging/deploy/maven2/" + def snapshotsRepoUrl = "https://oss.sonatype.org/content/repositories/snapshots/" + url = version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl + + credentials { + if (project.hasProperty('storedUsername') && project.hasProperty('storedPassword')) { + username project.storedUsername + password project.storedPassword + } + } + } + } + publications { + mavenJava(MavenPublication) { + if (!onlyPom) { + from components.java + artifact sourcesJar + artifact javadocJar + } + pom { + name = artifactId + if (onlyPom) { + packaging 'pom' + } else { + packaging 'jar' + } + // description = 'spring cloud stream redis .' + url = 'https://github.com/guoshiqiufeng/spring-cloud-stream-redis' + + scm { + connection = 'scm:git@github.com:guoshiqiufeng/spring-cloud-stream-redis.git' + developerConnection = 'scm:git@github.com:guoshiqiufeng/spring-cloud-stream-redis.git' + url = 'https://github.com/guoshiqiufeng/spring-cloud-stream-redis' + } + + licenses { + license { + name = 'The Apache License, Version 2.0' + url = 'https://www.apache.org/licenses/LICENSE-2.0.txt' + } + } + + developers { + developer { + id = 'fubluesky' + name = 'yanghq' + email = 'fubluesky@foxmail.com' + } + } + + withXml { + def root = asNode() + root.dependencies.'*'.findAll { + def d = it + d.scope.text() == 'runtime' && project.configurations.findByName("implementation").allDependencies.find { dep -> + dep.name == it.artifactId.text() + }.each() { + d.scope*.value = 'compile' + d.appendNode('optional', true) + } + } + } + } + } + } + + signing { + sign publishing.publications.mavenJava + } + } +} diff --git a/ext.gradle b/ext.gradle new file mode 100644 index 0000000..2909ec4 --- /dev/null +++ b/ext.gradle @@ -0,0 +1,13 @@ +ext { + configuration = [ + javaVersion = JavaVersion.VERSION_21 + ] + + libraries = [ + springBoot3Version = '3.2.7', + springCloudVersion = '2023.0.3' + ] + + lib = [ + ] +} diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..a9c3337 --- /dev/null +++ b/gradle.properties @@ -0,0 +1,4 @@ +# {x-release-please-start-version} +APP_VERSION=1.0.0-SNAPSHOT +# {x-release-please-end-version} +APP_GROUP=io.github.guoshiqiufeng.cloud diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..e644113 Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..a441313 --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,7 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip +networkTimeout=10000 +validateDistributionUrl=true +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew new file mode 100755 index 0000000..b740cf1 --- /dev/null +++ b/gradlew @@ -0,0 +1,249 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# 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 +# +# https://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. +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000..25da30d --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,92 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%"=="" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if %ERRORLEVEL% equ 0 goto execute + +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if %ERRORLEVEL% equ 0 goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/header.txt b/header.txt new file mode 100644 index 0000000..d4628f4 --- /dev/null +++ b/header.txt @@ -0,0 +1,13 @@ +Copyright (c) 2023-${year}, fubluesky (fubluesky@foxmail.com) + +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. diff --git a/settings.gradle b/settings.gradle new file mode 100644 index 0000000..dc45bd0 --- /dev/null +++ b/settings.gradle @@ -0,0 +1,28 @@ +buildscript { + repositories { + maven { url "https://maven.aliyun.com/repository/public" } + maven { url "https://maven.aliyun.com/repository/gradle-plugin" } + mavenCentral() + maven { url "https://plugins.gradle.org/m2/" } + } + + dependencies { + //noinspection DifferentKotlinGradleVersion + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.21" + classpath "gradle.plugin.com.hierynomus.gradle.plugins:license-gradle-plugin:0.16.1" + classpath "io.freefair.gradle:lombok-plugin:8.4" + classpath "io.spring.gradle:dependency-management-plugin:1.1.3" + } +} + +rootProject.name = 'root' + +include 'binders' +include 'binders:spring-cloud-stream-binder-redis-core' +include 'binders:spring-cloud-stream-binder-redis' +include 'binders:spring-cloud-starter-stream-redis' + +include 'bom' +// include 'bom:spring-cloud-starter-parent' +include 'bom:spring-cloud-stream-dependencies' + diff --git a/tools/redis/docker-compose.yml b/tools/redis/docker-compose.yml new file mode 100644 index 0000000..e6e5b05 --- /dev/null +++ b/tools/redis/docker-compose.yml @@ -0,0 +1,9 @@ +version: '3.8' + +services: + redis: + image: redis:latest + container_name: redis + ports: + - "6379:6379" + command: redis-server --appendonly yes