From 97485919ee7442755808ff787d5db9133e4c607e Mon Sep 17 00:00:00 2001 From: yanghq <1040926235@qq.com> Date: Thu, 14 Nov 2024 17:02:51 +0800 Subject: [PATCH 1/7] 0.4.0-SNAPSHOT --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 83e082a..1316473 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ # {x-release-please-start-version} -APP_VERSION=0.3.0 +APP_VERSION=0.4.0-SNAPSHOT # {x-release-please-end-version} APP_GROUP=io.github.guoshiqiufeng.cloud From bd9086ccc74a6a7a32ac10259f0eadb2b7c2e1bd Mon Sep 17 00:00:00 2001 From: yanghq <1040926235@qq.com> Date: Fri, 15 Nov 2024 09:29:45 +0800 Subject: [PATCH 2/7] doc: Add Maven central version --- docs/.vuepress/config.js | 10 +++++++ docs/en/guide/maven-central-version.md | 37 ++++++++++++++++++++++++++ docs/guide/maven-central-version.md | 37 ++++++++++++++++++++++++++ 3 files changed, 84 insertions(+) create mode 100644 docs/en/guide/maven-central-version.md create mode 100644 docs/guide/maven-central-version.md diff --git a/docs/.vuepress/config.js b/docs/.vuepress/config.js index ab8fe27..f995a19 100644 --- a/docs/.vuepress/config.js +++ b/docs/.vuepress/config.js @@ -114,6 +114,11 @@ export default defineUserConfig({ { text: '更新日志', link: 'https://github.com/guoshiqiufeng/spring-cloud-stream-redis/releases', + }, { + text: 'Maven central version', + children: [ + '/guide/maven-central-version' + ] } ] } @@ -199,6 +204,11 @@ export default defineUserConfig({ { text: 'Changelog', link: 'https://github.com/guoshiqiufeng/spring-cloud-stream-redis/releases', + }, { + text: 'Maven central version', + children: [ + '/en/guide/maven-central-version' + ] } ] } diff --git a/docs/en/guide/maven-central-version.md b/docs/en/guide/maven-central-version.md new file mode 100644 index 0000000..f4c0e32 --- /dev/null +++ b/docs/en/guide/maven-central-version.md @@ -0,0 +1,37 @@ + +## Maven central +### spring-cloud-stream-dependencies + +![Maven metadata URL](https://img.shields.io/maven-metadata/v?metadataUrl=https%3A%2F%2Frepo1.maven.org%2Fmaven2%2Fio%2Fgithub%2Fguoshiqiufeng%2Fcloud%2Fspring-cloud-stream-dependencies%2Fmaven-metadata.xml) + +### spring-cloud-starter-stream-redis + +![Maven metadata URL](https://img.shields.io/maven-metadata/v?metadataUrl=https%3A%2F%2Frepo1.maven.org%2Fmaven2%2Fio%2Fgithub%2Fguoshiqiufeng%2Fcloud%2Fspring-cloud-starter-stream-redis%2Fmaven-metadata.xml) + +### spring-cloud-stream-binder-redis + +![Maven metadata URL](https://img.shields.io/maven-metadata/v?metadataUrl=https%3A%2F%2Frepo1.maven.org%2Fmaven2%2Fio%2Fgithub%2Fguoshiqiufeng%2Fcloud%2Fspring-cloud-stream-binder-redis%2Fmaven-metadata.xml) + +### spring-cloud-stream-binder-redis-core + +![Maven metadata URL](https://img.shields.io/maven-metadata/v?metadataUrl=https%3A%2F%2Frepo1.maven.org%2Fmaven2%2Fio%2Fgithub%2Fguoshiqiufeng%2Fcloud%2Fspring-cloud-stream-binder-redis-core%2Fmaven-metadata.xml) + + + +## AliYun Maven central +### spring-cloud-stream-dependencies + +![Maven metadata URL](https://img.shields.io/maven-metadata/v?metadataUrl=https%3A%2F%2Fmaven.aliyun.com%2Frepository%2Fpublic%2Fio%2Fgithub%2Fguoshiqiufeng%2Fcloud%2Fspring-cloud-stream-dependencies%2Fmaven-metadata.xml) + +### spring-cloud-starter-stream-redis + +![Maven metadata URL](https://img.shields.io/maven-metadata/v?metadataUrl=https%3A%2F%2Fmaven.aliyun.com%2Frepository%2Fpublic%2Fio%2Fgithub%2Fguoshiqiufeng%2Fcloud%2Fspring-cloud-starter-stream-redis%2Fmaven-metadata.xml) + +### spring-cloud-stream-binder-redis + +![Maven metadata URL](https://img.shields.io/maven-metadata/v?metadataUrl=https%3A%2F%2Fmaven.aliyun.com%2Frepository%2Fpublic%2Fio%2Fgithub%2Fguoshiqiufeng%2Fcloud%2Fspring-cloud-stream-binder-redis%2Fmaven-metadata.xml) + +### spring-cloud-stream-binder-redis-core + +![Maven metadata URL](https://img.shields.io/maven-metadata/v?metadataUrl=https%3A%2F%2Fmaven.aliyun.com%2Frepository%2Fpublic%2Fio%2Fgithub%2Fguoshiqiufeng%2Fcloud%2Fspring-cloud-stream-binder-redis-core%2Fmaven-metadata.xml) + diff --git a/docs/guide/maven-central-version.md b/docs/guide/maven-central-version.md new file mode 100644 index 0000000..f4c0e32 --- /dev/null +++ b/docs/guide/maven-central-version.md @@ -0,0 +1,37 @@ + +## Maven central +### spring-cloud-stream-dependencies + +![Maven metadata URL](https://img.shields.io/maven-metadata/v?metadataUrl=https%3A%2F%2Frepo1.maven.org%2Fmaven2%2Fio%2Fgithub%2Fguoshiqiufeng%2Fcloud%2Fspring-cloud-stream-dependencies%2Fmaven-metadata.xml) + +### spring-cloud-starter-stream-redis + +![Maven metadata URL](https://img.shields.io/maven-metadata/v?metadataUrl=https%3A%2F%2Frepo1.maven.org%2Fmaven2%2Fio%2Fgithub%2Fguoshiqiufeng%2Fcloud%2Fspring-cloud-starter-stream-redis%2Fmaven-metadata.xml) + +### spring-cloud-stream-binder-redis + +![Maven metadata URL](https://img.shields.io/maven-metadata/v?metadataUrl=https%3A%2F%2Frepo1.maven.org%2Fmaven2%2Fio%2Fgithub%2Fguoshiqiufeng%2Fcloud%2Fspring-cloud-stream-binder-redis%2Fmaven-metadata.xml) + +### spring-cloud-stream-binder-redis-core + +![Maven metadata URL](https://img.shields.io/maven-metadata/v?metadataUrl=https%3A%2F%2Frepo1.maven.org%2Fmaven2%2Fio%2Fgithub%2Fguoshiqiufeng%2Fcloud%2Fspring-cloud-stream-binder-redis-core%2Fmaven-metadata.xml) + + + +## AliYun Maven central +### spring-cloud-stream-dependencies + +![Maven metadata URL](https://img.shields.io/maven-metadata/v?metadataUrl=https%3A%2F%2Fmaven.aliyun.com%2Frepository%2Fpublic%2Fio%2Fgithub%2Fguoshiqiufeng%2Fcloud%2Fspring-cloud-stream-dependencies%2Fmaven-metadata.xml) + +### spring-cloud-starter-stream-redis + +![Maven metadata URL](https://img.shields.io/maven-metadata/v?metadataUrl=https%3A%2F%2Fmaven.aliyun.com%2Frepository%2Fpublic%2Fio%2Fgithub%2Fguoshiqiufeng%2Fcloud%2Fspring-cloud-starter-stream-redis%2Fmaven-metadata.xml) + +### spring-cloud-stream-binder-redis + +![Maven metadata URL](https://img.shields.io/maven-metadata/v?metadataUrl=https%3A%2F%2Fmaven.aliyun.com%2Frepository%2Fpublic%2Fio%2Fgithub%2Fguoshiqiufeng%2Fcloud%2Fspring-cloud-stream-binder-redis%2Fmaven-metadata.xml) + +### spring-cloud-stream-binder-redis-core + +![Maven metadata URL](https://img.shields.io/maven-metadata/v?metadataUrl=https%3A%2F%2Fmaven.aliyun.com%2Frepository%2Fpublic%2Fio%2Fgithub%2Fguoshiqiufeng%2Fcloud%2Fspring-cloud-stream-binder-redis-core%2Fmaven-metadata.xml) + From 551944e19a4838d2f1e03130ef0fe5784da251cb Mon Sep 17 00:00:00 2001 From: yanghq <1040926235@qq.com> Date: Mon, 18 Nov 2024 10:50:14 +0800 Subject: [PATCH 3/7] feat: RedisBinderHealthIndicator --- .../converter/MessagingMessageConverter.java | 15 +++ ...edisBinderConfigurationPropertiesTest.java | 9 +- .../build.gradle | 2 +- .../config/RedisBinderConfiguration.java | 3 +- ...disBinderHealthIndicatorConfiguration.java | 41 +++++++ .../health/RedisBinderHealthIndicator.java | 74 +++++++++++++ ...sBinderHealthIndicatorIntegrationTest.java | 45 ++++++++ .../RedisBinderHealthIndicatorTest.java | 101 ++++++++++++++++++ docs/en/guide/maven-central-version.md | 5 +- docs/guide/maven-central-version.md | 5 +- 10 files changed, 288 insertions(+), 12 deletions(-) create mode 100644 binders/spring-cloud-stream-binder-redis/src/main/java/io/github/guoshiqiufeng/cloud/stream/binder/redis/config/RedisBinderHealthIndicatorConfiguration.java create mode 100644 binders/spring-cloud-stream-binder-redis/src/main/java/io/github/guoshiqiufeng/cloud/stream/binder/redis/health/RedisBinderHealthIndicator.java create mode 100644 binders/spring-cloud-stream-binder-redis/src/test/java/io/github/guoshiqiufeng/cloud/stream/binder/redis/health/RedisBinderHealthIndicatorIntegrationTest.java create mode 100644 binders/spring-cloud-stream-binder-redis/src/test/java/io/github/guoshiqiufeng/cloud/stream/binder/redis/health/RedisBinderHealthIndicatorTest.java diff --git a/binders/spring-cloud-stream-binder-redis-core/src/main/java/io/github/guoshiqiufeng/cloud/stream/binder/redis/support/converter/MessagingMessageConverter.java b/binders/spring-cloud-stream-binder-redis-core/src/main/java/io/github/guoshiqiufeng/cloud/stream/binder/redis/support/converter/MessagingMessageConverter.java index 8676dcf..3e05c53 100644 --- a/binders/spring-cloud-stream-binder-redis-core/src/main/java/io/github/guoshiqiufeng/cloud/stream/binder/redis/support/converter/MessagingMessageConverter.java +++ b/binders/spring-cloud-stream-binder-redis-core/src/main/java/io/github/guoshiqiufeng/cloud/stream/binder/redis/support/converter/MessagingMessageConverter.java @@ -1,3 +1,18 @@ +/* + * Copyright (c) 2023-2024, 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. + */ package io.github.guoshiqiufeng.cloud.stream.binder.redis.support.converter; import org.jetbrains.annotations.NotNull; 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 index 5c21e06..a80ec2d 100644 --- 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 @@ -16,6 +16,7 @@ package io.github.guoshiqiufeng.cloud.stream.binder.redis.properties; import org.junit.jupiter.api.Test; +import org.springframework.boot.autoconfigure.data.redis.RedisProperties; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -30,19 +31,19 @@ public class RedisBinderConfigurationPropertiesTest { void testDefaultProperties() { RedisProperties redisProperties = new RedisProperties(); RedisBinderConfigurationProperties properties = new RedisBinderConfigurationProperties(redisProperties); - + assertEquals("localhost", properties.getConfiguration().getHost()); assertEquals(6379, properties.getConfiguration().getPort()); } - @Test + @Test void testCustomProperties() { RedisProperties redisProperties = new RedisProperties(); redisProperties.setHost("redis.example.com"); redisProperties.setPort(6380); - + RedisBinderConfigurationProperties properties = new RedisBinderConfigurationProperties(redisProperties); - + assertEquals("redis.example.com", properties.getConfiguration().getHost()); assertEquals(6380, properties.getConfiguration().getPort()); } diff --git a/binders/spring-cloud-stream-binder-redis/build.gradle b/binders/spring-cloud-stream-binder-redis/build.gradle index dca05a9..5c3cb0b 100644 --- a/binders/spring-cloud-stream-binder-redis/build.gradle +++ b/binders/spring-cloud-stream-binder-redis/build.gradle @@ -1,7 +1,7 @@ dependencies { api project(":binders:spring-cloud-stream-binder-redis-core") - annotationProcessor "org.springframework.boot:spring-boot-starter-actuator" + implementation "org.springframework.boot:spring-boot-starter-actuator" annotationProcessor "org.springframework.boot:spring-boot-configuration-processor" annotationProcessor "org.springframework.boot:spring-boot-autoconfigure" 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 index b847a88..f9af70a 100644 --- 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 @@ -31,6 +31,7 @@ import org.springframework.cloud.stream.config.ProducerMessageHandlerCustomizer; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Import; import org.springframework.data.redis.listener.RedisMessageListenerContainer; import org.springframework.integration.redis.inbound.RedisStoreMessageSource; @@ -41,7 +42,7 @@ */ @Configuration(proxyBeanMethods = false) @ConditionalOnMissingBean(Binder.class) -// @Import({RedisBinderHealthIndicatorConfiguration.class}) +@Import({RedisBinderHealthIndicatorConfiguration.class}) @EnableConfigurationProperties({RedisProperties.class, RedisExtendedBindingProperties.class}) public class RedisBinderConfiguration { diff --git a/binders/spring-cloud-stream-binder-redis/src/main/java/io/github/guoshiqiufeng/cloud/stream/binder/redis/config/RedisBinderHealthIndicatorConfiguration.java b/binders/spring-cloud-stream-binder-redis/src/main/java/io/github/guoshiqiufeng/cloud/stream/binder/redis/config/RedisBinderHealthIndicatorConfiguration.java new file mode 100644 index 0000000..5778db1 --- /dev/null +++ b/binders/spring-cloud-stream-binder-redis/src/main/java/io/github/guoshiqiufeng/cloud/stream/binder/redis/config/RedisBinderHealthIndicatorConfiguration.java @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2023-2024, 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. + */ +package io.github.guoshiqiufeng.cloud.stream.binder.redis.config; + +import io.github.guoshiqiufeng.cloud.stream.binder.redis.health.RedisBinderHealthIndicator; +import org.springframework.boot.actuate.autoconfigure.health.ConditionalOnEnabledHealthIndicator; +import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.data.redis.connection.RedisConnectionFactory; + +/** + * Configuration for Redis binder health indicators. + * + * @author yanghq + * @version 1.0 + * @since 2024/11/17 10:55 + */ +@Configuration(proxyBeanMethods = false) +@ConditionalOnClass(name = "org.springframework.boot.actuate.health.HealthIndicator") +public class RedisBinderHealthIndicatorConfiguration { + + @Bean + @ConditionalOnEnabledHealthIndicator("redis") + public RedisBinderHealthIndicator redisBinderHealthIndicator(RedisConnectionFactory connectionFactory) { + return new RedisBinderHealthIndicator(connectionFactory); + } +} diff --git a/binders/spring-cloud-stream-binder-redis/src/main/java/io/github/guoshiqiufeng/cloud/stream/binder/redis/health/RedisBinderHealthIndicator.java b/binders/spring-cloud-stream-binder-redis/src/main/java/io/github/guoshiqiufeng/cloud/stream/binder/redis/health/RedisBinderHealthIndicator.java new file mode 100644 index 0000000..f0729bb --- /dev/null +++ b/binders/spring-cloud-stream-binder-redis/src/main/java/io/github/guoshiqiufeng/cloud/stream/binder/redis/health/RedisBinderHealthIndicator.java @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2023-2024, 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. + */ +package io.github.guoshiqiufeng.cloud.stream.binder.redis.health; + +import org.springframework.boot.actuate.health.AbstractHealthIndicator; +import org.springframework.boot.actuate.health.Health; +import org.springframework.data.redis.connection.RedisConnection; +import org.springframework.data.redis.connection.RedisConnectionFactory; +import org.springframework.util.Assert; + +import java.util.Properties; + +/** + * Health indicator for Redis binder. + * + * @author yanghq + * @version 1.0 + * @since 2024/11/17 10:00 + */ +public class RedisBinderHealthIndicator extends AbstractHealthIndicator { + + private static final String REDIS_PONG_RESPONSE = "PONG"; + private static final String REDIS_VERSION_KEY = "redis_version"; + private static final String REDIS_MODE_KEY = "redis_mode"; + private static final String SERVER_INFO_SECTION = "server"; + + private final RedisConnectionFactory connectionFactory; + + public RedisBinderHealthIndicator(RedisConnectionFactory connectionFactory) { + super("Redis health check failed"); + Assert.notNull(connectionFactory, "RedisConnectionFactory must not be null"); + this.connectionFactory = connectionFactory; + } + + @Override + protected void doHealthCheck(Health.Builder builder) throws Exception { + try (RedisConnection connection = connectionFactory.getConnection()) { + String result = connection.ping(); + if (REDIS_PONG_RESPONSE.equals(result)) { + Properties serverInfo = connection.serverCommands().info(SERVER_INFO_SECTION); + if (serverInfo != null) { + String version = serverInfo.getProperty(REDIS_VERSION_KEY); + String mode = serverInfo.getProperty(REDIS_MODE_KEY); + builder.up() + .withDetail("version", version != null ? version : "unknown") + .withDetail("mode", mode != null ? mode : "unknown"); + } else { + builder.up() + .withDetail("version", "unknown") + .withDetail("mode", "unknown"); + } + } else { + builder.down() + .withDetail("ping", result); + } + } catch (Exception e) { + builder.down() + .withException(e); + } + } +} diff --git a/binders/spring-cloud-stream-binder-redis/src/test/java/io/github/guoshiqiufeng/cloud/stream/binder/redis/health/RedisBinderHealthIndicatorIntegrationTest.java b/binders/spring-cloud-stream-binder-redis/src/test/java/io/github/guoshiqiufeng/cloud/stream/binder/redis/health/RedisBinderHealthIndicatorIntegrationTest.java new file mode 100644 index 0000000..2fb382d --- /dev/null +++ b/binders/spring-cloud-stream-binder-redis/src/test/java/io/github/guoshiqiufeng/cloud/stream/binder/redis/health/RedisBinderHealthIndicatorIntegrationTest.java @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2023-2024, 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. + */ +package io.github.guoshiqiufeng.cloud.stream.binder.redis.health; + +import io.github.guoshiqiufeng.cloud.stream.binder.redis.RedisContainerTest; +import org.junit.jupiter.api.Test; +import org.springframework.boot.actuate.health.Health; +import org.springframework.boot.actuate.health.Status; +import org.springframework.data.redis.connection.RedisConnectionFactory; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author yanghq + * @version 1.0 + * @since 2024/11/17 17:04 + */ +class RedisBinderHealthIndicatorIntegrationTest implements RedisContainerTest { + + @Test + void shouldReportHealthWithRealRedis() { + RedisConnectionFactory connectionFactory = RedisContainerTest.connectionFactory(); + + RedisBinderHealthIndicator healthIndicator = new RedisBinderHealthIndicator(connectionFactory); + Health health = healthIndicator.health(); + + assertThat(health.getStatus()).isEqualTo(Status.UP); + assertThat(health.getDetails()) + .containsKey("version") + .containsKey("mode"); + } +} diff --git a/binders/spring-cloud-stream-binder-redis/src/test/java/io/github/guoshiqiufeng/cloud/stream/binder/redis/health/RedisBinderHealthIndicatorTest.java b/binders/spring-cloud-stream-binder-redis/src/test/java/io/github/guoshiqiufeng/cloud/stream/binder/redis/health/RedisBinderHealthIndicatorTest.java new file mode 100644 index 0000000..fea5198 --- /dev/null +++ b/binders/spring-cloud-stream-binder-redis/src/test/java/io/github/guoshiqiufeng/cloud/stream/binder/redis/health/RedisBinderHealthIndicatorTest.java @@ -0,0 +1,101 @@ +/* + * Copyright (c) 2023-2024, 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. + */ +package io.github.guoshiqiufeng.cloud.stream.binder.redis.health; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.actuate.health.Health; +import org.springframework.boot.actuate.health.Status; +import org.springframework.data.redis.connection.RedisConnection; +import org.springframework.data.redis.connection.RedisConnectionFactory; +import org.springframework.data.redis.connection.RedisServerCommands; + +import java.util.Properties; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.*; + +/** + * @author yanghq + * @version 1.0 + * @since 2024/11/17 17:04 + */ +class RedisBinderHealthIndicatorTest { + + private static final String REDIS_PONG_RESPONSE = "PONG"; + private static final String REDIS_VERSION_KEY = "redis_version"; + private static final String REDIS_MODE_KEY = "redis_mode"; + private static final String SERVER_INFO_SECTION = "server"; + + @Test + void healthUp() { + RedisConnectionFactory connectionFactory = mock(RedisConnectionFactory.class); + RedisConnection redisConnection = mock(RedisConnection.class); + RedisServerCommands serverCommands = mock(RedisServerCommands.class); + + when(connectionFactory.getConnection()).thenReturn(redisConnection); + when(redisConnection.ping()).thenReturn(REDIS_PONG_RESPONSE); + when(redisConnection.serverCommands()).thenReturn(serverCommands); + + // Mock Redis info command response + Properties serverInfo = new Properties(); + serverInfo.setProperty(REDIS_VERSION_KEY, "7.0.2"); + serverInfo.setProperty(REDIS_MODE_KEY, "standalone"); + when(serverCommands.info(SERVER_INFO_SECTION)).thenReturn(serverInfo); + + RedisBinderHealthIndicator healthIndicator = new RedisBinderHealthIndicator(connectionFactory); + Health health = healthIndicator.health(); + + assertThat(health.getStatus()).isEqualTo(Status.UP); + assertThat(health.getDetails()) + .containsEntry("version", "7.0.2") + .containsEntry("mode", "standalone"); + + verify(redisConnection).close(); + } + + @Test + void healthDown() { + RedisConnectionFactory connectionFactory = mock(RedisConnectionFactory.class); + RedisConnection redisConnection = mock(RedisConnection.class); + + when(connectionFactory.getConnection()).thenReturn(redisConnection); + when(redisConnection.ping()).thenReturn("ERROR"); + + RedisBinderHealthIndicator healthIndicator = new RedisBinderHealthIndicator(connectionFactory); + Health health = healthIndicator.health(); + + assertThat(health.getStatus()).isEqualTo(Status.DOWN); + assertThat(health.getDetails()) + .containsEntry("ping", "ERROR"); + + verify(redisConnection).close(); + } + + @Test + void healthDownOnException() { + RedisConnectionFactory connectionFactory = mock(RedisConnectionFactory.class); + when(connectionFactory.getConnection()) + .thenThrow(new RuntimeException("Connection failed")); + + RedisBinderHealthIndicator healthIndicator = new RedisBinderHealthIndicator(connectionFactory); + Health health = healthIndicator.health(); + + assertThat(health.getStatus()).isEqualTo(Status.DOWN); + assertThat(health.getDetails()) + .containsKey("error") + .containsValue("java.lang.RuntimeException: Connection failed"); + } +} diff --git a/docs/en/guide/maven-central-version.md b/docs/en/guide/maven-central-version.md index f4c0e32..92dbcfb 100644 --- a/docs/en/guide/maven-central-version.md +++ b/docs/en/guide/maven-central-version.md @@ -1,5 +1,5 @@ - ## Maven central + ### spring-cloud-stream-dependencies ![Maven metadata URL](https://img.shields.io/maven-metadata/v?metadataUrl=https%3A%2F%2Frepo1.maven.org%2Fmaven2%2Fio%2Fgithub%2Fguoshiqiufeng%2Fcloud%2Fspring-cloud-stream-dependencies%2Fmaven-metadata.xml) @@ -16,9 +16,8 @@ ![Maven metadata URL](https://img.shields.io/maven-metadata/v?metadataUrl=https%3A%2F%2Frepo1.maven.org%2Fmaven2%2Fio%2Fgithub%2Fguoshiqiufeng%2Fcloud%2Fspring-cloud-stream-binder-redis-core%2Fmaven-metadata.xml) - - ## AliYun Maven central + ### spring-cloud-stream-dependencies ![Maven metadata URL](https://img.shields.io/maven-metadata/v?metadataUrl=https%3A%2F%2Fmaven.aliyun.com%2Frepository%2Fpublic%2Fio%2Fgithub%2Fguoshiqiufeng%2Fcloud%2Fspring-cloud-stream-dependencies%2Fmaven-metadata.xml) diff --git a/docs/guide/maven-central-version.md b/docs/guide/maven-central-version.md index f4c0e32..92dbcfb 100644 --- a/docs/guide/maven-central-version.md +++ b/docs/guide/maven-central-version.md @@ -1,5 +1,5 @@ - ## Maven central + ### spring-cloud-stream-dependencies ![Maven metadata URL](https://img.shields.io/maven-metadata/v?metadataUrl=https%3A%2F%2Frepo1.maven.org%2Fmaven2%2Fio%2Fgithub%2Fguoshiqiufeng%2Fcloud%2Fspring-cloud-stream-dependencies%2Fmaven-metadata.xml) @@ -16,9 +16,8 @@ ![Maven metadata URL](https://img.shields.io/maven-metadata/v?metadataUrl=https%3A%2F%2Frepo1.maven.org%2Fmaven2%2Fio%2Fgithub%2Fguoshiqiufeng%2Fcloud%2Fspring-cloud-stream-binder-redis-core%2Fmaven-metadata.xml) - - ## AliYun Maven central + ### spring-cloud-stream-dependencies ![Maven metadata URL](https://img.shields.io/maven-metadata/v?metadataUrl=https%3A%2F%2Fmaven.aliyun.com%2Frepository%2Fpublic%2Fio%2Fgithub%2Fguoshiqiufeng%2Fcloud%2Fspring-cloud-stream-dependencies%2Fmaven-metadata.xml) From e733805a1ad90f2348952bc204ace0339a36d43b Mon Sep 17 00:00:00 2001 From: yanghq <1040926235@qq.com> Date: Mon, 18 Nov 2024 11:34:18 +0800 Subject: [PATCH 4/7] dependency: Update spring boot version to 3.2.11 --- README-zh.md | 4 ++-- README.md | 4 ++-- ext.gradle | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README-zh.md b/README-zh.md index af03e47..91180d2 100644 --- a/README-zh.md +++ b/README-zh.md @@ -16,8 +16,8 @@ https://guoshiqiufeng.github.io/spring-cloud-stream-redis/ ### 开发框架 -- Spring Cloud Stream 4.1.3 -- Spring Boot +- Spring Cloud Stream 4 +- Spring Boot 3 ### 功能 diff --git a/README.md b/README.md index 4bcc51a..65783b4 100644 --- a/README.md +++ b/README.md @@ -17,8 +17,8 @@ https://guoshiqiufeng.github.io/spring-cloud-stream-redis/en/ ### Development Framework -- Spring Cloud Stream 4.1.3 -- Spring Boot +- Spring Cloud Stream 4 +- Spring Boot 3 ### Features diff --git a/ext.gradle b/ext.gradle index 91be1e1..693b3c1 100644 --- a/ext.gradle +++ b/ext.gradle @@ -4,7 +4,7 @@ ext { ] libraries = [ - springBoot3Version = '3.2.7', + springBoot3Version = '3.2.11', springCloudStreamVersion = '4.1.3' ] From 50fa1d60fca9e56dc8fd08dd589e63a517776ef9 Mon Sep 17 00:00:00 2001 From: yanghq <1040926235@qq.com> Date: Tue, 19 Nov 2024 10:17:13 +0800 Subject: [PATCH 5/7] fix: Change RedisBinderHealthIndicator to inherit from RedisHealthIndicator. --- ...disBinderHealthIndicatorConfiguration.java | 11 ++++- .../redis/health/RedisBinderHealth.java | 12 +++++ .../health/RedisBinderHealthIndicator.java | 47 ++----------------- .../RedisBinderHealthIndicatorTest.java | 14 +++--- 4 files changed, 31 insertions(+), 53 deletions(-) create mode 100644 binders/spring-cloud-stream-binder-redis/src/main/java/io/github/guoshiqiufeng/cloud/stream/binder/redis/health/RedisBinderHealth.java diff --git a/binders/spring-cloud-stream-binder-redis/src/main/java/io/github/guoshiqiufeng/cloud/stream/binder/redis/config/RedisBinderHealthIndicatorConfiguration.java b/binders/spring-cloud-stream-binder-redis/src/main/java/io/github/guoshiqiufeng/cloud/stream/binder/redis/config/RedisBinderHealthIndicatorConfiguration.java index 5778db1..c3471a7 100644 --- a/binders/spring-cloud-stream-binder-redis/src/main/java/io/github/guoshiqiufeng/cloud/stream/binder/redis/config/RedisBinderHealthIndicatorConfiguration.java +++ b/binders/spring-cloud-stream-binder-redis/src/main/java/io/github/guoshiqiufeng/cloud/stream/binder/redis/config/RedisBinderHealthIndicatorConfiguration.java @@ -15,9 +15,13 @@ */ package io.github.guoshiqiufeng.cloud.stream.binder.redis.config; +import io.github.guoshiqiufeng.cloud.stream.binder.redis.health.RedisBinderHealth; import io.github.guoshiqiufeng.cloud.stream.binder.redis.health.RedisBinderHealthIndicator; +import io.github.guoshiqiufeng.cloud.stream.binder.redis.properties.RedisBinderConfigurationProperties; +import io.github.guoshiqiufeng.cloud.stream.binder.redis.utils.RedisConnectionFactoryUtil; import org.springframework.boot.actuate.autoconfigure.health.ConditionalOnEnabledHealthIndicator; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.data.redis.connection.RedisConnectionFactory; @@ -31,11 +35,14 @@ */ @Configuration(proxyBeanMethods = false) @ConditionalOnClass(name = "org.springframework.boot.actuate.health.HealthIndicator") +@ConditionalOnEnabledHealthIndicator("binders") +@ConditionalOnMissingBean(RedisBinderHealth.class) public class RedisBinderHealthIndicatorConfiguration { @Bean - @ConditionalOnEnabledHealthIndicator("redis") - public RedisBinderHealthIndicator redisBinderHealthIndicator(RedisConnectionFactory connectionFactory) { + public RedisBinderHealthIndicator redisBinderHealthIndicator(RedisBinderConfigurationProperties configurationProperties) { + RedisConnectionFactory connectionFactory = RedisConnectionFactoryUtil.getRedisConnectionFactory( + configurationProperties.getConfiguration()); return new RedisBinderHealthIndicator(connectionFactory); } } diff --git a/binders/spring-cloud-stream-binder-redis/src/main/java/io/github/guoshiqiufeng/cloud/stream/binder/redis/health/RedisBinderHealth.java b/binders/spring-cloud-stream-binder-redis/src/main/java/io/github/guoshiqiufeng/cloud/stream/binder/redis/health/RedisBinderHealth.java new file mode 100644 index 0000000..40ff42a --- /dev/null +++ b/binders/spring-cloud-stream-binder-redis/src/main/java/io/github/guoshiqiufeng/cloud/stream/binder/redis/health/RedisBinderHealth.java @@ -0,0 +1,12 @@ +package io.github.guoshiqiufeng.cloud.stream.binder.redis.health; + +import org.springframework.boot.actuate.health.HealthIndicator; + +/** + * Health indicator for Redis binder. + * @author yanghq + * @version 1.0 + * @since 2024/11/18 15:07 + */ +public interface RedisBinderHealth extends HealthIndicator { +} diff --git a/binders/spring-cloud-stream-binder-redis/src/main/java/io/github/guoshiqiufeng/cloud/stream/binder/redis/health/RedisBinderHealthIndicator.java b/binders/spring-cloud-stream-binder-redis/src/main/java/io/github/guoshiqiufeng/cloud/stream/binder/redis/health/RedisBinderHealthIndicator.java index f0729bb..34c35dc 100644 --- a/binders/spring-cloud-stream-binder-redis/src/main/java/io/github/guoshiqiufeng/cloud/stream/binder/redis/health/RedisBinderHealthIndicator.java +++ b/binders/spring-cloud-stream-binder-redis/src/main/java/io/github/guoshiqiufeng/cloud/stream/binder/redis/health/RedisBinderHealthIndicator.java @@ -15,13 +15,8 @@ */ package io.github.guoshiqiufeng.cloud.stream.binder.redis.health; -import org.springframework.boot.actuate.health.AbstractHealthIndicator; -import org.springframework.boot.actuate.health.Health; -import org.springframework.data.redis.connection.RedisConnection; +import org.springframework.boot.actuate.data.redis.RedisHealthIndicator; import org.springframework.data.redis.connection.RedisConnectionFactory; -import org.springframework.util.Assert; - -import java.util.Properties; /** * Health indicator for Redis binder. @@ -30,45 +25,9 @@ * @version 1.0 * @since 2024/11/17 10:00 */ -public class RedisBinderHealthIndicator extends AbstractHealthIndicator { - - private static final String REDIS_PONG_RESPONSE = "PONG"; - private static final String REDIS_VERSION_KEY = "redis_version"; - private static final String REDIS_MODE_KEY = "redis_mode"; - private static final String SERVER_INFO_SECTION = "server"; - - private final RedisConnectionFactory connectionFactory; +public class RedisBinderHealthIndicator extends RedisHealthIndicator { public RedisBinderHealthIndicator(RedisConnectionFactory connectionFactory) { - super("Redis health check failed"); - Assert.notNull(connectionFactory, "RedisConnectionFactory must not be null"); - this.connectionFactory = connectionFactory; - } - - @Override - protected void doHealthCheck(Health.Builder builder) throws Exception { - try (RedisConnection connection = connectionFactory.getConnection()) { - String result = connection.ping(); - if (REDIS_PONG_RESPONSE.equals(result)) { - Properties serverInfo = connection.serverCommands().info(SERVER_INFO_SECTION); - if (serverInfo != null) { - String version = serverInfo.getProperty(REDIS_VERSION_KEY); - String mode = serverInfo.getProperty(REDIS_MODE_KEY); - builder.up() - .withDetail("version", version != null ? version : "unknown") - .withDetail("mode", mode != null ? mode : "unknown"); - } else { - builder.up() - .withDetail("version", "unknown") - .withDetail("mode", "unknown"); - } - } else { - builder.down() - .withDetail("ping", result); - } - } catch (Exception e) { - builder.down() - .withException(e); - } + super(connectionFactory); } } diff --git a/binders/spring-cloud-stream-binder-redis/src/test/java/io/github/guoshiqiufeng/cloud/stream/binder/redis/health/RedisBinderHealthIndicatorTest.java b/binders/spring-cloud-stream-binder-redis/src/test/java/io/github/guoshiqiufeng/cloud/stream/binder/redis/health/RedisBinderHealthIndicatorTest.java index fea5198..7a0deb8 100644 --- a/binders/spring-cloud-stream-binder-redis/src/test/java/io/github/guoshiqiufeng/cloud/stream/binder/redis/health/RedisBinderHealthIndicatorTest.java +++ b/binders/spring-cloud-stream-binder-redis/src/test/java/io/github/guoshiqiufeng/cloud/stream/binder/redis/health/RedisBinderHealthIndicatorTest.java @@ -36,8 +36,6 @@ class RedisBinderHealthIndicatorTest { private static final String REDIS_PONG_RESPONSE = "PONG"; private static final String REDIS_VERSION_KEY = "redis_version"; - private static final String REDIS_MODE_KEY = "redis_mode"; - private static final String SERVER_INFO_SECTION = "server"; @Test void healthUp() { @@ -52,16 +50,14 @@ void healthUp() { // Mock Redis info command response Properties serverInfo = new Properties(); serverInfo.setProperty(REDIS_VERSION_KEY, "7.0.2"); - serverInfo.setProperty(REDIS_MODE_KEY, "standalone"); - when(serverCommands.info(SERVER_INFO_SECTION)).thenReturn(serverInfo); + when(serverCommands.info()).thenReturn(serverInfo); RedisBinderHealthIndicator healthIndicator = new RedisBinderHealthIndicator(connectionFactory); Health health = healthIndicator.health(); assertThat(health.getStatus()).isEqualTo(Status.UP); assertThat(health.getDetails()) - .containsEntry("version", "7.0.2") - .containsEntry("mode", "standalone"); + .containsEntry("version", "7.0.2"); verify(redisConnection).close(); } @@ -70,16 +66,20 @@ void healthUp() { void healthDown() { RedisConnectionFactory connectionFactory = mock(RedisConnectionFactory.class); RedisConnection redisConnection = mock(RedisConnection.class); + RedisServerCommands serverCommands = mock(RedisServerCommands.class); when(connectionFactory.getConnection()).thenReturn(redisConnection); when(redisConnection.ping()).thenReturn("ERROR"); + when(redisConnection.serverCommands()).thenReturn(serverCommands); + when(serverCommands.info()).thenThrow(new RuntimeException("Redis is down")); RedisBinderHealthIndicator healthIndicator = new RedisBinderHealthIndicator(connectionFactory); Health health = healthIndicator.health(); assertThat(health.getStatus()).isEqualTo(Status.DOWN); assertThat(health.getDetails()) - .containsEntry("ping", "ERROR"); + .containsKey("error") + .containsValue("java.lang.RuntimeException: Redis is down"); verify(redisConnection).close(); } From b21222e3bacc88388223f92b83fffdbae82ab826 Mon Sep 17 00:00:00 2001 From: yanghq <1040926235@qq.com> Date: Tue, 19 Nov 2024 10:27:35 +0800 Subject: [PATCH 6/7] doc: Add actuator documentation --- docs/.vuepress/config.js | 4 +++ docs/en/guide/actuator.md | 55 +++++++++++++++++++++++++++++++++++++++ docs/guide/actuator.md | 55 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 114 insertions(+) create mode 100644 docs/en/guide/actuator.md create mode 100644 docs/guide/actuator.md diff --git a/docs/.vuepress/config.js b/docs/.vuepress/config.js index f995a19..5aa4ff7 100644 --- a/docs/.vuepress/config.js +++ b/docs/.vuepress/config.js @@ -60,6 +60,7 @@ export default defineUserConfig({ '/guide/getting-started', '/guide/install', '/guide/config', + '/guide/actuator', // '/guide/annotation', ] }, @@ -90,6 +91,7 @@ export default defineUserConfig({ '/guide/getting-started', '/guide/install', '/guide/config', + '/guide/actuator', // '/guide/annotation', // { // text: '发送消息', @@ -149,6 +151,7 @@ export default defineUserConfig({ '/en/guide/getting-started', '/en/guide/install', '/en/guide/config', + '/en/guide/actuator', // '/en/guide/annotation', ] }, @@ -180,6 +183,7 @@ export default defineUserConfig({ '/en/guide/getting-started', '/en/guide/install', '/en/guide/config', + '/en/guide/actuator', // '/en/guide/annotation', // { // text: 'Send message', diff --git a/docs/en/guide/actuator.md b/docs/en/guide/actuator.md new file mode 100644 index 0000000..b92c287 --- /dev/null +++ b/docs/en/guide/actuator.md @@ -0,0 +1,55 @@ +--- +lang: en-US +title: Actuator +description: Actuator +--- + +# Actuator + +> ake sure you have spring-cloud-stream-redis installed,if you haven't, check out the [Install](install.md)。 + +## Enable configuration + +```yaml:no-line-numbers +management: + endpoints: + web: + exposure: + include: '*' + endpoint: + health: + show-details: always + health: + binders: + enabled: true + redis: + enabled: false +``` + +## Access path + +`/actuator/health` + +Example: + +```json:no-line-numbers +{ + "status": "UP", + "components": { + "binders": { + "status": "UP", + "components": { + "redis": { + "status": "UP", + "details": { + "version": "7.1.2" + } + } + } + }, + "ping": { + "status": "UP" + } + } +} +``` \ No newline at end of file diff --git a/docs/guide/actuator.md b/docs/guide/actuator.md new file mode 100644 index 0000000..9b4fb20 --- /dev/null +++ b/docs/guide/actuator.md @@ -0,0 +1,55 @@ +--- +lang: zh-cn +title: 健康检查 +description: +--- + +# 健康检查 + +> 请确保您已经安装了 spring-cloud-stream-redis,如果您尚未安装,请查看 [安装](install.md)。 + +## 开启配置 + +```yaml:no-line-numbers +management: + endpoints: + web: + exposure: + include: '*' + endpoint: + health: + show-details: always + health: + binders: + enabled: true + redis: + enabled: false +``` + +## 访问路径 + +`/actuator/health` + +示例: + +```json:no-line-numbers +{ + "status": "UP", + "components": { + "binders": { + "status": "UP", + "components": { + "redis": { + "status": "UP", + "details": { + "version": "7.1.2" + } + } + } + }, + "ping": { + "status": "UP" + } + } +} +``` \ No newline at end of file From 448507daa66d63bc1c196f917d791bb69d01f11d Mon Sep 17 00:00:00 2001 From: yanghq <1040926235@qq.com> Date: Thu, 21 Nov 2024 10:17:27 +0800 Subject: [PATCH 7/7] release: 0.4.0 --- README-zh.md | 2 +- README.md | 2 +- gradle.properties | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README-zh.md b/README-zh.md index 91180d2..6c32fbd 100644 --- a/README-zh.md +++ b/README-zh.md @@ -39,7 +39,7 @@ https://guoshiqiufeng.github.io/spring-cloud-stream-redis/ io.github.guoshiqiufeng.cloud spring-cloud-stream-dependencies - 0.3.0 + 0.4.0 import diff --git a/README.md b/README.md index 65783b4..f3b4b5b 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,7 @@ https://guoshiqiufeng.github.io/spring-cloud-stream-redis/en/ io.github.guoshiqiufeng.cloud spring-cloud-stream-dependencies - 0.3.0 + 0.4.0 import diff --git a/gradle.properties b/gradle.properties index 1316473..76a022c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ # {x-release-please-start-version} -APP_VERSION=0.4.0-SNAPSHOT +APP_VERSION=0.4.0 # {x-release-please-end-version} APP_GROUP=io.github.guoshiqiufeng.cloud