From 1390ebb31bba0313d366fe5a31d87cd3394c601b Mon Sep 17 00:00:00 2001 From: Ladislav Thon Date: Wed, 11 Oct 2023 16:12:21 +0200 Subject: [PATCH] Redis Client: add deployment SPI module 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 | 5 ++++ .../redis/deployment/RedisCacheProcessor.java | 2 +- .../redis-client/deployment-spi/pom.xml | 26 ++++++++++++++++++ .../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 | 1 + 9 files changed, 73 insertions(+), 3 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%) diff --git a/bom/application/pom.xml b/bom/application/pom.xml index d11b9987818c67..6ca2d3dd93b414 100644 --- a/bom/application/pom.xml +++ b/bom/application/pom.xml @@ -5957,6 +5957,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..5b6d30e42029de --- /dev/null +++ b/extensions/redis-client/deployment-spi/pom.xml @@ -0,0 +1,26 @@ + + + + quarkus-redis-client-parent + io.quarkus + 999-SNAPSHOT + + 4.0.0 + + quarkus-redis-client-deployment-spi + Quarkus - Redis Client - Deployment SPI + + + + io.quarkus + quarkus-core-deployment + + + io.quarkus + quarkus-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..d3f800372cbdf7 100644 --- a/extensions/redis-client/pom.xml +++ b/extensions/redis-client/pom.xml @@ -18,6 +18,7 @@ deployment + deployment-spi runtime