Skip to content

Commit

Permalink
Redis Client: add runtime SPI and deployment SPI modules
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Ladicek committed Oct 18, 2023
1 parent 549833a commit 83e6c83
Show file tree
Hide file tree
Showing 13 changed files with 113 additions and 6 deletions.
10 changes: 10 additions & 0 deletions bom/application/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5967,6 +5967,11 @@
<artifactId>quarkus-redis-client</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-redis-client-runtime-spi</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-redis-cache</artifactId>
Expand All @@ -5978,6 +5983,11 @@
<artifactId>quarkus-redis-client-deployment</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-redis-client-deployment-spi</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-redis-cache-deployment</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
30 changes: 30 additions & 0 deletions extensions/redis-client/deployment-spi/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>quarkus-redis-client-parent</artifactId>
<groupId>io.quarkus</groupId>
<version>999-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>quarkus-redis-client-deployment-spi</artifactId>
<name>Quarkus - Redis Client - Deployment SPI</name>

<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-redis-client-runtime-spi</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-core-deployment</artifactId>
</dependency>
<dependency>
<groupId>io.smallrye.reactive</groupId>
<artifactId>smallrye-mutiny-vertx-redis-client</artifactId>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -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<Redis> client;
private final String name;

public RedisClientBuildItem(Supplier<Redis> client, String name) {
this.client = client;
this.name = name;
}

public Supplier<Redis> getClient() {
return client;
}

public String getName() {
return name;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.quarkus.redis.deployment.client;
package io.quarkus.redis.deployment.client.spi;

import io.quarkus.builder.item.MultiBuildItem;

Expand Down
4 changes: 4 additions & 0 deletions extensions/redis-client/deployment/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-redis-client</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-redis-client-deployment-spi</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-smallrye-health-spi</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -127,7 +129,8 @@ public void init(
VertxBuildItem vertxBuildItem,
ApplicationArchivesBuildItem applicationArchivesBuildItem, LaunchModeBuildItem launchMode,
BuildProducer<NativeImageResourceBuildItem> nativeImageResources,
BuildProducer<HotDeploymentWatchedFileBuildItem> hotDeploymentWatchedFiles) {
BuildProducer<HotDeploymentWatchedFileBuildItem> hotDeploymentWatchedFiles,
BuildProducer<RedisClientBuildItem> clientSuppliers) {

// Collect the used redis clients, the unused clients will not be instantiated.
Set<String> names = new HashSet<>();
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 2 additions & 0 deletions extensions/redis-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@

<modules>
<module>deployment</module>
<module>deployment-spi</module>
<module>runtime</module>
<module>runtime-spi</module>
</modules>


Expand Down
15 changes: 15 additions & 0 deletions extensions/redis-client/runtime-spi/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>quarkus-redis-client-parent</artifactId>
<groupId>io.quarkus</groupId>
<version>999-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>quarkus-redis-client-runtime-spi</artifactId>
<name>Quarkus - Redis Client - Runtime SPI</name>

</project>
Original file line number Diff line number Diff line change
@@ -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 = "<default>";
}
4 changes: 4 additions & 0 deletions extensions/redis-client/runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
<groupId>io.smallrye.reactive</groupId>
<artifactId>smallrye-mutiny-vertx-redis-client</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-redis-client-runtime-spi</artifactId>
</dependency>
<!-- Add the health extension as optional as we will produce the health check only if it's included -->
<dependency>
<groupId>io.quarkus</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 = "<default>";
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
Expand Down

0 comments on commit 83e6c83

Please sign in to comment.