From c61d7b0931d8d9fe1074613593ada7ccc5b5b378 Mon Sep 17 00:00:00 2001 From: Ladislav Thon Date: Wed, 11 Oct 2023 16:12:21 +0200 Subject: [PATCH] Redis Client: add runtime SPI and deployment SPI modules Some constants from the Redis Client runtime module are moved to the runtime SPI module, so that they can be used from other modules that cannot directly depend on the Redis Client extension. One build item, `RequestedRedisClientBuildItem`, is moved from the Redis Client deployment module to the deployment SPI module. This is technically a breaking change, because it is also moved to a different package, but this build item doesn't seem to be used anywhere outside of Quarkus, so it should be safe. Further, one new build item, `RedisClientBuildItem`, is added. It provides runtime access to the Redis clients (in the Mutiny variant) without having to perform a CDI lookup. --- bom/application/pom.xml | 10 +++++++ .../redis/deployment/RedisCacheProcessor.java | 2 +- .../redis-client/deployment-spi/pom.xml | 30 +++++++++++++++++++ .../client/spi/RedisClientBuildItem.java | 27 +++++++++++++++++ .../spi}/RequestedRedisClientBuildItem.java | 2 +- extensions/redis-client/deployment/pom.xml | 4 +++ .../client/RedisClientProcessor.java | 8 ++++- .../client/RedisDatasourceProcessor.java | 1 + extensions/redis-client/pom.xml | 2 ++ extensions/redis-client/runtime-spi/pom.xml | 15 ++++++++++ .../redis/runtime/spi/RedisConstants.java | 7 +++++ extensions/redis-client/runtime/pom.xml | 4 +++ .../runtime/client/config/RedisConfig.java | 7 +++-- 13 files changed, 113 insertions(+), 6 deletions(-) create mode 100644 extensions/redis-client/deployment-spi/pom.xml create mode 100644 extensions/redis-client/deployment-spi/src/main/java/io/quarkus/redis/deployment/client/spi/RedisClientBuildItem.java rename extensions/redis-client/{deployment/src/main/java/io/quarkus/redis/deployment/client => deployment-spi/src/main/java/io/quarkus/redis/deployment/client/spi}/RequestedRedisClientBuildItem.java (86%) create mode 100644 extensions/redis-client/runtime-spi/pom.xml create mode 100644 extensions/redis-client/runtime-spi/src/main/java/io/quarkus/redis/runtime/spi/RedisConstants.java diff --git a/bom/application/pom.xml b/bom/application/pom.xml index 3474d103d52e63..49e80c3eb98d3f 100644 --- a/bom/application/pom.xml +++ b/bom/application/pom.xml @@ -5961,6 +5961,11 @@ quarkus-redis-client ${project.version} + + io.quarkus + quarkus-redis-client-runtime-spi + ${project.version} + io.quarkus quarkus-redis-cache @@ -5972,6 +5977,11 @@ quarkus-redis-client-deployment ${project.version} + + io.quarkus + quarkus-redis-client-deployment-spi + ${project.version} + io.quarkus quarkus-redis-cache-deployment diff --git a/extensions/redis-cache/deployment/src/main/java/io/quarkus/cache/redis/deployment/RedisCacheProcessor.java b/extensions/redis-cache/deployment/src/main/java/io/quarkus/cache/redis/deployment/RedisCacheProcessor.java index 4de5b1628d3f43..2325b45656a246 100644 --- a/extensions/redis-cache/deployment/src/main/java/io/quarkus/cache/redis/deployment/RedisCacheProcessor.java +++ b/extensions/redis-cache/deployment/src/main/java/io/quarkus/cache/redis/deployment/RedisCacheProcessor.java @@ -34,7 +34,7 @@ import io.quarkus.deployment.annotations.Record; import io.quarkus.deployment.builditem.CombinedIndexBuildItem; import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem; -import io.quarkus.redis.deployment.client.RequestedRedisClientBuildItem; +import io.quarkus.redis.deployment.client.spi.RequestedRedisClientBuildItem; import io.quarkus.redis.runtime.client.config.RedisConfig; import io.smallrye.mutiny.Uni; diff --git a/extensions/redis-client/deployment-spi/pom.xml b/extensions/redis-client/deployment-spi/pom.xml new file mode 100644 index 00000000000000..236a49220a79ce --- /dev/null +++ b/extensions/redis-client/deployment-spi/pom.xml @@ -0,0 +1,30 @@ + + + + quarkus-redis-client-parent + io.quarkus + 999-SNAPSHOT + + 4.0.0 + + quarkus-redis-client-deployment-spi + Quarkus - Redis Client - Deployment SPI + + + + io.quarkus + quarkus-redis-client-runtime-spi + + + io.quarkus + quarkus-core-deployment + + + io.smallrye.reactive + smallrye-mutiny-vertx-redis-client + + + + diff --git a/extensions/redis-client/deployment-spi/src/main/java/io/quarkus/redis/deployment/client/spi/RedisClientBuildItem.java b/extensions/redis-client/deployment-spi/src/main/java/io/quarkus/redis/deployment/client/spi/RedisClientBuildItem.java new file mode 100644 index 00000000000000..dae9a2d7a64ad5 --- /dev/null +++ b/extensions/redis-client/deployment-spi/src/main/java/io/quarkus/redis/deployment/client/spi/RedisClientBuildItem.java @@ -0,0 +1,27 @@ +package io.quarkus.redis.deployment.client.spi; + +import java.util.function.Supplier; + +import io.quarkus.builder.item.MultiBuildItem; +import io.vertx.mutiny.redis.client.Redis; + +/** + * Provides runtime access to the Redis clients, in the Mutiny variant. + */ +public final class RedisClientBuildItem extends MultiBuildItem { + private final Supplier client; + private final String name; + + public RedisClientBuildItem(Supplier client, String name) { + this.client = client; + this.name = name; + } + + public Supplier getClient() { + return client; + } + + public String getName() { + return name; + } +} diff --git a/extensions/redis-client/deployment/src/main/java/io/quarkus/redis/deployment/client/RequestedRedisClientBuildItem.java b/extensions/redis-client/deployment-spi/src/main/java/io/quarkus/redis/deployment/client/spi/RequestedRedisClientBuildItem.java similarity index 86% rename from extensions/redis-client/deployment/src/main/java/io/quarkus/redis/deployment/client/RequestedRedisClientBuildItem.java rename to extensions/redis-client/deployment-spi/src/main/java/io/quarkus/redis/deployment/client/spi/RequestedRedisClientBuildItem.java index a35af3572769c9..4dc1b3ee5604e2 100644 --- a/extensions/redis-client/deployment/src/main/java/io/quarkus/redis/deployment/client/RequestedRedisClientBuildItem.java +++ b/extensions/redis-client/deployment-spi/src/main/java/io/quarkus/redis/deployment/client/spi/RequestedRedisClientBuildItem.java @@ -1,4 +1,4 @@ -package io.quarkus.redis.deployment.client; +package io.quarkus.redis.deployment.client.spi; import io.quarkus.builder.item.MultiBuildItem; diff --git a/extensions/redis-client/deployment/pom.xml b/extensions/redis-client/deployment/pom.xml index e18a963cfe2c4e..f267e7df637979 100644 --- a/extensions/redis-client/deployment/pom.xml +++ b/extensions/redis-client/deployment/pom.xml @@ -31,6 +31,10 @@ io.quarkus quarkus-redis-client + + io.quarkus + quarkus-redis-client-deployment-spi + io.quarkus quarkus-smallrye-health-spi diff --git a/extensions/redis-client/deployment/src/main/java/io/quarkus/redis/deployment/client/RedisClientProcessor.java b/extensions/redis-client/deployment/src/main/java/io/quarkus/redis/deployment/client/RedisClientProcessor.java index 55308b824e85d1..bdaeed05a6a538 100644 --- a/extensions/redis-client/deployment/src/main/java/io/quarkus/redis/deployment/client/RedisClientProcessor.java +++ b/extensions/redis-client/deployment/src/main/java/io/quarkus/redis/deployment/client/RedisClientProcessor.java @@ -48,6 +48,8 @@ import io.quarkus.redis.client.RedisHostsProvider; import io.quarkus.redis.client.RedisOptionsCustomizer; import io.quarkus.redis.client.reactive.ReactiveRedisClient; +import io.quarkus.redis.deployment.client.spi.RedisClientBuildItem; +import io.quarkus.redis.deployment.client.spi.RequestedRedisClientBuildItem; import io.quarkus.redis.runtime.client.RedisClientRecorder; import io.quarkus.redis.runtime.client.config.RedisConfig; import io.quarkus.runtime.LaunchMode; @@ -127,7 +129,8 @@ public void init( VertxBuildItem vertxBuildItem, ApplicationArchivesBuildItem applicationArchivesBuildItem, LaunchModeBuildItem launchMode, BuildProducer nativeImageResources, - BuildProducer hotDeploymentWatchedFiles) { + BuildProducer hotDeploymentWatchedFiles, + BuildProducer clientSuppliers) { // Collect the used redis clients, the unused clients will not be instantiated. Set names = new HashSet<>(); @@ -177,6 +180,9 @@ public void init( .produce(configureAndCreateSyntheticBean(name, RedisClient.class, recorder.getLegacyRedisClient(name))); syntheticBeans.produce(configureAndCreateSyntheticBean(name, ReactiveRedisClient.class, recorder.getLegacyReactiveRedisClient(name))); + + // build items + clientSuppliers.produce(new RedisClientBuildItem(recorder.getRedisClient(name), name)); } recorder.cleanup(shutdown); diff --git a/extensions/redis-client/deployment/src/main/java/io/quarkus/redis/deployment/client/RedisDatasourceProcessor.java b/extensions/redis-client/deployment/src/main/java/io/quarkus/redis/deployment/client/RedisDatasourceProcessor.java index a9c8679b768a25..9944fe65a9ced7 100644 --- a/extensions/redis-client/deployment/src/main/java/io/quarkus/redis/deployment/client/RedisDatasourceProcessor.java +++ b/extensions/redis-client/deployment/src/main/java/io/quarkus/redis/deployment/client/RedisDatasourceProcessor.java @@ -30,6 +30,7 @@ import io.quarkus.redis.datasource.ReactiveRedisDataSource; import io.quarkus.redis.datasource.RedisDataSource; import io.quarkus.redis.datasource.codecs.Codec; +import io.quarkus.redis.deployment.client.spi.RequestedRedisClientBuildItem; import io.quarkus.redis.runtime.client.RedisClientRecorder; import io.quarkus.vertx.deployment.VertxBuildItem; diff --git a/extensions/redis-client/pom.xml b/extensions/redis-client/pom.xml index 458b2563a75bfe..c861fb139cc9f7 100644 --- a/extensions/redis-client/pom.xml +++ b/extensions/redis-client/pom.xml @@ -18,7 +18,9 @@ deployment + deployment-spi runtime + runtime-spi diff --git a/extensions/redis-client/runtime-spi/pom.xml b/extensions/redis-client/runtime-spi/pom.xml new file mode 100644 index 00000000000000..49ac4286499245 --- /dev/null +++ b/extensions/redis-client/runtime-spi/pom.xml @@ -0,0 +1,15 @@ + + + + quarkus-redis-client-parent + io.quarkus + 999-SNAPSHOT + + 4.0.0 + + quarkus-redis-client-runtime-spi + Quarkus - Redis Client - Runtime SPI + + diff --git a/extensions/redis-client/runtime-spi/src/main/java/io/quarkus/redis/runtime/spi/RedisConstants.java b/extensions/redis-client/runtime-spi/src/main/java/io/quarkus/redis/runtime/spi/RedisConstants.java new file mode 100644 index 00000000000000..d810e83009f323 --- /dev/null +++ b/extensions/redis-client/runtime-spi/src/main/java/io/quarkus/redis/runtime/spi/RedisConstants.java @@ -0,0 +1,7 @@ +package io.quarkus.redis.runtime.spi; + +public class RedisConstants { + public static final String REDIS_CONFIG_ROOT_NAME = "redis"; + public static final String HOSTS_CONFIG_NAME = "hosts"; + public static final String DEFAULT_CLIENT_NAME = ""; +} diff --git a/extensions/redis-client/runtime/pom.xml b/extensions/redis-client/runtime/pom.xml index f00b8e2c6715e2..3dd920a374e64b 100644 --- a/extensions/redis-client/runtime/pom.xml +++ b/extensions/redis-client/runtime/pom.xml @@ -27,6 +27,10 @@ io.smallrye.reactive smallrye-mutiny-vertx-redis-client + + io.quarkus + quarkus-redis-client-runtime-spi + io.quarkus diff --git a/extensions/redis-client/runtime/src/main/java/io/quarkus/redis/runtime/client/config/RedisConfig.java b/extensions/redis-client/runtime/src/main/java/io/quarkus/redis/runtime/client/config/RedisConfig.java index ac13188c6338b4..f6b2171d6c0608 100644 --- a/extensions/redis-client/runtime/src/main/java/io/quarkus/redis/runtime/client/config/RedisConfig.java +++ b/extensions/redis-client/runtime/src/main/java/io/quarkus/redis/runtime/client/config/RedisConfig.java @@ -2,6 +2,7 @@ import java.util.Map; +import io.quarkus.redis.runtime.spi.RedisConstants; import io.quarkus.runtime.annotations.ConfigDocMapKey; import io.quarkus.runtime.annotations.ConfigPhase; import io.quarkus.runtime.annotations.ConfigRoot; @@ -12,9 +13,9 @@ @ConfigRoot(phase = ConfigPhase.RUN_TIME) public interface RedisConfig { - public final static String REDIS_CONFIG_ROOT_NAME = "redis"; - public final static String HOSTS_CONFIG_NAME = "hosts"; - public static final String DEFAULT_CLIENT_NAME = ""; + public final static String REDIS_CONFIG_ROOT_NAME = RedisConstants.REDIS_CONFIG_ROOT_NAME; + public final static String HOSTS_CONFIG_NAME = RedisConstants.HOSTS_CONFIG_NAME; + public static final String DEFAULT_CLIENT_NAME = RedisConstants.DEFAULT_CLIENT_NAME; /** * The default redis client