From 4307179cd73af462c511f8b21bedbef929b88b7e Mon Sep 17 00:00:00 2001 From: "mehmet.ari" Date: Mon, 10 May 2021 09:49:10 +0300 Subject: [PATCH] disable jdempotent with config --- Jdempotent-core/pom.xml | 2 +- Jdempotent-spring-boot-redis-starter/pom.xml | 4 +- .../jdempotent/redis/ApplicationConfig.java | 4 +- .../redis/RedisConfigProperties.java | 2 +- .../redis/RedisEnvironmentPostProcessor.java | 50 +++++++++++++++++++ .../redis/RedisSentinelConfiguration.java | 2 +- .../main/resources/META-INF/spring.factories | 5 +- README.md | 17 ++++++- examples/jdempotent-redis-example/pom.xml | 2 +- pom.xml | 2 +- 10 files changed, 78 insertions(+), 12 deletions(-) create mode 100644 Jdempotent-spring-boot-redis-starter/src/main/java/com/trendyol/jdempotent/redis/RedisEnvironmentPostProcessor.java diff --git a/Jdempotent-core/pom.xml b/Jdempotent-core/pom.xml index c917c9d..d9ca0a4 100644 --- a/Jdempotent-core/pom.xml +++ b/Jdempotent-core/pom.xml @@ -6,7 +6,7 @@ 4.0.0 com.trendyol Jdempotent-core - 1.0.3 + 1.0.4 Jdempotent-core jar https://github.com/Trendyol/Jdempotent/tree/master/Jdempotent-core diff --git a/Jdempotent-spring-boot-redis-starter/pom.xml b/Jdempotent-spring-boot-redis-starter/pom.xml index fa6b062..cdb4746 100644 --- a/Jdempotent-spring-boot-redis-starter/pom.xml +++ b/Jdempotent-spring-boot-redis-starter/pom.xml @@ -6,7 +6,7 @@ 4.0.0 com.trendyol Jdempotent-spring-boot-redis-starter - 1.0.3 + 1.0.4 Jdempotent-spring-boot-redis-starter jar https://github.com/Trendyol/Jdempotent/tree/master/Jdempotent-spring-boot-redis-starter @@ -54,7 +54,7 @@ com.trendyol Jdempotent-core - 1.0.3 + 1.0.4 redis.clients diff --git a/Jdempotent-spring-boot-redis-starter/src/main/java/com/trendyol/jdempotent/redis/ApplicationConfig.java b/Jdempotent-spring-boot-redis-starter/src/main/java/com/trendyol/jdempotent/redis/ApplicationConfig.java index c7bd735..bf85f5e 100644 --- a/Jdempotent-spring-boot-redis-starter/src/main/java/com/trendyol/jdempotent/redis/ApplicationConfig.java +++ b/Jdempotent-spring-boot-redis-starter/src/main/java/com/trendyol/jdempotent/redis/ApplicationConfig.java @@ -14,7 +14,7 @@ */ @Configuration @ConditionalOnProperty( - value = "jdempotent.enable", + prefix="jdempotent", name = "enable", havingValue = "true", matchIfMissing = true) public class ApplicationConfig { @@ -27,7 +27,7 @@ public ApplicationConfig(RedisConfigProperties redisProperties) { @Bean @ConditionalOnProperty( - value = "jdempotent.enable", + prefix="jdempotent", name = "enable", havingValue = "true", matchIfMissing = true) @ConditionalOnClass(ErrorConditionalCallback.class) diff --git a/Jdempotent-spring-boot-redis-starter/src/main/java/com/trendyol/jdempotent/redis/RedisConfigProperties.java b/Jdempotent-spring-boot-redis-starter/src/main/java/com/trendyol/jdempotent/redis/RedisConfigProperties.java index 3051ca0..28ae991 100644 --- a/Jdempotent-spring-boot-redis-starter/src/main/java/com/trendyol/jdempotent/redis/RedisConfigProperties.java +++ b/Jdempotent-spring-boot-redis-starter/src/main/java/com/trendyol/jdempotent/redis/RedisConfigProperties.java @@ -12,7 +12,7 @@ */ @Configuration @ConditionalOnProperty( - value = "jdempotent.enable", + prefix="jdempotent", name = "enable", havingValue = "true", matchIfMissing = true) public class RedisConfigProperties { diff --git a/Jdempotent-spring-boot-redis-starter/src/main/java/com/trendyol/jdempotent/redis/RedisEnvironmentPostProcessor.java b/Jdempotent-spring-boot-redis-starter/src/main/java/com/trendyol/jdempotent/redis/RedisEnvironmentPostProcessor.java new file mode 100644 index 0000000..f3fc40b --- /dev/null +++ b/Jdempotent-spring-boot-redis-starter/src/main/java/com/trendyol/jdempotent/redis/RedisEnvironmentPostProcessor.java @@ -0,0 +1,50 @@ +package com.trendyol.jdempotent.redis; + +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; + +import java.util.HashMap; +import java.util.Map; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.env.EnvironmentPostProcessor; +import org.springframework.core.env.ConfigurableEnvironment; +import org.springframework.core.env.MapPropertySource; +import org.springframework.core.env.MutablePropertySources; +import org.springframework.core.env.PropertySource; + +@ConditionalOnProperty( + prefix="jdempotent", name = "enable", + havingValue = "true", + matchIfMissing = true) +public class RedisEnvironmentPostProcessor implements EnvironmentPostProcessor { + private static final String PROPERTY_SOURCE_NAME = "defaultProperties"; + + @Override + public void postProcessEnvironment(ConfigurableEnvironment environment, + SpringApplication application) { + Map map = new HashMap(); + map.put("spring.data.redis.repositories.enabled", "false"); + addOrReplace(environment.getPropertySources(), map); + } + + private void addOrReplace(MutablePropertySources propertySources, + Map map) { + MapPropertySource target = null; + if (propertySources.contains(PROPERTY_SOURCE_NAME)) { + PropertySource source = propertySources.get(PROPERTY_SOURCE_NAME); + if (source instanceof MapPropertySource) { + target = (MapPropertySource) source; + for (String key : map.keySet()) { + if (!target.containsProperty(key)) { + target.getSource().put(key, map.get(key)); + } + } + } + } + if (target == null) { + target = new MapPropertySource(PROPERTY_SOURCE_NAME, map); + } + if (!propertySources.contains(PROPERTY_SOURCE_NAME)) { + propertySources.addLast(target); + } + } +} diff --git a/Jdempotent-spring-boot-redis-starter/src/main/java/com/trendyol/jdempotent/redis/RedisSentinelConfiguration.java b/Jdempotent-spring-boot-redis-starter/src/main/java/com/trendyol/jdempotent/redis/RedisSentinelConfiguration.java index 2aa6905..c45d679 100644 --- a/Jdempotent-spring-boot-redis-starter/src/main/java/com/trendyol/jdempotent/redis/RedisSentinelConfiguration.java +++ b/Jdempotent-spring-boot-redis-starter/src/main/java/com/trendyol/jdempotent/redis/RedisSentinelConfiguration.java @@ -18,7 +18,7 @@ */ @Configuration @ConditionalOnProperty( - value = "jdempotent.enable", + prefix="jdempotent", name = "enable", havingValue = "true", matchIfMissing = true) public class RedisSentinelConfiguration { diff --git a/Jdempotent-spring-boot-redis-starter/src/main/resources/META-INF/spring.factories b/Jdempotent-spring-boot-redis-starter/src/main/resources/META-INF/spring.factories index 1975fd2..6ef0076 100644 --- a/Jdempotent-spring-boot-redis-starter/src/main/resources/META-INF/spring.factories +++ b/Jdempotent-spring-boot-redis-starter/src/main/resources/META-INF/spring.factories @@ -1,4 +1,7 @@ org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ com.trendyol.jdempotent.redis.ApplicationConfig,\ com.trendyol.jdempotent.redis.RedisConfigProperties,\ -com.trendyol.jdempotent.redis.RedisSentinelConfiguration \ No newline at end of file +com.trendyol.jdempotent.redis.RedisSentinelConfiguration,\ +org.springframework.boot.autoconfigure.data.redis.RedisRepositoriesAutoConfiguration +org.springframework.boot.env.EnvironmentPostProcessor=\ +com.trendyol.jdempotent.redis.RedisEnvironmentPostProcessor \ No newline at end of file diff --git a/README.md b/README.md index 7ed269e..78dc59b 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ Make your listener or etc idempotent easily com.trendyol Jdempotent-spring-boot-redis-starter - 1.0.3 + 1.0.4 ``` @@ -61,7 +61,7 @@ public class AspectConditionalCallback implements ErrorConditionalCallback { } ``` -4 - Let's make redis configuration +4 - Let's make redis configuration. ```yaml jdempotent: @@ -81,6 +81,19 @@ jdempotent: expireTimeoutHour: 3 ``` +Also you can disable jdempotent any time for example you don't have circut breaker but your redis down etc. +You can wish disable jdempotent with following configuration. + +```yaml + enable: false +``` + +```java +@SpringBootApplication( + exclude = { RedisAutoConfiguration.class, RedisRepositoriesAutoConfiguration.class } +) +``` + ### Performance As it is shown in the following image, the most cpu consuming part of jdempotent is getting a redis connection so we don't need to worry performance related issues. diff --git a/examples/jdempotent-redis-example/pom.xml b/examples/jdempotent-redis-example/pom.xml index 52d40d1..7b08513 100644 --- a/examples/jdempotent-redis-example/pom.xml +++ b/examples/jdempotent-redis-example/pom.xml @@ -59,7 +59,7 @@ com.trendyol Jdempotent-spring-boot-redis-starter - 1.0.3 + 1.0.4 diff --git a/pom.xml b/pom.xml index b992948..049d4b0 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.trendyol jdempotent pom - 1.0.3 + 1.0.4 Jdempotent https://github.com/Trendyol/Jdempotent Jdempotent