Skip to content

Commit

Permalink
disable jdempotent with config
Browse files Browse the repository at this point in the history
  • Loading branch information
mehmet.ari committed May 10, 2021
1 parent 3342ff7 commit 4307179
Show file tree
Hide file tree
Showing 10 changed files with 78 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Jdempotent-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.trendyol</groupId>
<artifactId>Jdempotent-core</artifactId>
<version>1.0.3</version>
<version>1.0.4</version>
<name>Jdempotent-core</name>
<packaging>jar</packaging>
<url>https://github.com/Trendyol/Jdempotent/tree/master/Jdempotent-core</url>
Expand Down
4 changes: 2 additions & 2 deletions Jdempotent-spring-boot-redis-starter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.trendyol</groupId>
<artifactId>Jdempotent-spring-boot-redis-starter</artifactId>
<version>1.0.3</version>
<version>1.0.4</version>
<name>Jdempotent-spring-boot-redis-starter</name>
<packaging>jar</packaging>
<url>https://github.com/Trendyol/Jdempotent/tree/master/Jdempotent-spring-boot-redis-starter</url>
Expand Down Expand Up @@ -54,7 +54,7 @@
<dependency>
<groupId>com.trendyol</groupId>
<artifactId>Jdempotent-core</artifactId>
<version>1.0.3</version>
<version>1.0.4</version>
</dependency>
<dependency>
<groupId>redis.clients</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/
@Configuration
@ConditionalOnProperty(
value = "jdempotent.enable",
prefix="jdempotent", name = "enable",
havingValue = "true",
matchIfMissing = true)
public class ApplicationConfig {
Expand All @@ -27,7 +27,7 @@ public ApplicationConfig(RedisConfigProperties redisProperties) {

@Bean
@ConditionalOnProperty(
value = "jdempotent.enable",
prefix="jdempotent", name = "enable",
havingValue = "true",
matchIfMissing = true)
@ConditionalOnClass(ErrorConditionalCallback.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*/
@Configuration
@ConditionalOnProperty(
value = "jdempotent.enable",
prefix="jdempotent", name = "enable",
havingValue = "true",
matchIfMissing = true)
public class RedisConfigProperties {
Expand Down
Original file line number Diff line number Diff line change
@@ -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<String, Object> map = new HashMap<String, Object>();
map.put("spring.data.redis.repositories.enabled", "false");
addOrReplace(environment.getPropertySources(), map);
}

private void addOrReplace(MutablePropertySources propertySources,
Map<String, Object> 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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
@Configuration
@ConditionalOnProperty(
value = "jdempotent.enable",
prefix="jdempotent", name = "enable",
havingValue = "true",
matchIfMissing = true)
public class RedisSentinelConfiguration {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.trendyol.jdempotent.redis.ApplicationConfig,\
com.trendyol.jdempotent.redis.RedisConfigProperties,\
com.trendyol.jdempotent.redis.RedisSentinelConfiguration
com.trendyol.jdempotent.redis.RedisSentinelConfiguration,\
org.springframework.boot.autoconfigure.data.redis.RedisRepositoriesAutoConfiguration
org.springframework.boot.env.EnvironmentPostProcessor=\
com.trendyol.jdempotent.redis.RedisEnvironmentPostProcessor
17 changes: 15 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Make your listener or etc idempotent easily
<dependency>
<groupId>com.trendyol</groupId>
<artifactId>Jdempotent-spring-boot-redis-starter</artifactId>
<version>1.0.3</version>
<version>1.0.4</version>
</dependency>
```

Expand Down Expand Up @@ -61,7 +61,7 @@ public class AspectConditionalCallback implements ErrorConditionalCallback {
}
```

4 - Let's make redis configuration
4 - Let's make redis configuration.

```yaml
jdempotent:
Expand All @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion examples/jdempotent-redis-example/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
<dependency>
<groupId>com.trendyol</groupId>
<artifactId>Jdempotent-spring-boot-redis-starter</artifactId>
<version>1.0.3</version>
<version>1.0.4</version>
</dependency>
</dependencies>

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>com.trendyol</groupId>
<artifactId>jdempotent</artifactId>
<packaging>pom</packaging>
<version>1.0.3</version>
<version>1.0.4</version>
<name>Jdempotent</name>
<url>https://github.com/Trendyol/Jdempotent</url>
<description>Jdempotent</description>
Expand Down

0 comments on commit 4307179

Please sign in to comment.