Skip to content

Commit 2a10bb3

Browse files
committed
Make Stork optional for REST Client
If you want to use Stork, you now have to add the quarkus-smallrye-stork extension, which IMHO makes perfect sense. This avoids initializing Stork for every application using the REST Client. Fixes quarkusio#47337
1 parent 2f397be commit 2a10bb3

File tree

11 files changed

+67
-23
lines changed

11 files changed

+67
-23
lines changed

core/deployment/src/main/java/io/quarkus/deployment/Capability.java

+1
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ public interface Capability {
127127
String SMALLRYE_OPENAPI = QUARKUS_PREFIX + ".smallrye.openapi";
128128
String SMALLRYE_GRAPHQL = QUARKUS_PREFIX + ".smallrye.graphql";
129129
String SMALLRYE_FAULT_TOLERANCE = QUARKUS_PREFIX + ".smallrye.faulttolerance";
130+
String SMALLRYE_STORK = QUARKUS_PREFIX + ".smallrye.stork";
130131

131132
String SPRING_WEB = QUARKUS_PREFIX + ".spring.web";
132133

docs/src/main/asciidoc/stork-kubernetes.adoc

+2-2
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,10 @@ The various integrations in Quarkus extract the location of the service from tha
6161

6262
== Bootstrapping the project
6363

64-
Create a Quarkus project importing the quarkus-rest-client and quarkus-rest extensions using your favorite approach:
64+
Create a Quarkus project importing the quarkus-rest-client, quarkus-rest, and quarkus-smallrye-stork extensions using your favorite approach:
6565

6666
:create-app-artifact-id: stork-kubernetes-quickstart
67-
:create-app-extensions: quarkus-rest-client,quarkus-rest
67+
:create-app-extensions: quarkus-rest-client,quarkus-rest,quarkus-smallrye-stork
6868
include::{includes}/devtools/create-app.adoc[]
6969

7070
In the generated project, also add the following dependencies:

docs/src/main/asciidoc/stork.adoc

+2-2
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,10 @@ image::stork-process.png[Discovery and Selection of services,width=50%, align=ce
7070

7171
== Bootstrapping the project
7272

73-
Create a Quarkus project importing the quarkus-rest-client and quarkus-rest extensions using your favorite approach:
73+
Create a Quarkus project importing the quarkus-rest-client, quarkus-rest, and quarkus-smallrye-stork extensions using your favorite approach:
7474

7575
:create-app-artifact-id: stork-quickstart
76-
:create-app-extensions: quarkus-rest-client,quarkus-rest
76+
:create-app-extensions: quarkus-rest-client,quarkus-rest,quarkus-smallrye-stork
7777
include::{includes}/devtools/create-app.adoc[]
7878

7979
In the generated project, also add the following dependencies:

extensions/micrometer/deployment/pom.xml

+6
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,12 @@
9191
<scope>test</scope>
9292
</dependency>
9393

94+
<dependency>
95+
<groupId>io.quarkus</groupId>
96+
<artifactId>quarkus-smallrye-stork-deployment</artifactId>
97+
<scope>test</scope>
98+
</dependency>
99+
94100
<dependency>
95101
<groupId>io.quarkus</groupId>
96102
<artifactId>quarkus-rest-jackson-deployment</artifactId>

extensions/resteasy-reactive/rest-client-jaxrs/deployment/src/main/java/io/quarkus/jaxrs/client/reactive/deployment/JaxrsClientReactiveProcessor.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -259,9 +259,14 @@ void initializeRuntimeInitializedClasses(BuildProducer<RuntimeInitializedClassBu
259259
}
260260

261261
@BuildStep
262-
void initializeStorkFilter(BuildProducer<AdditionalBeanBuildItem> additionalBeans,
262+
void initializeStorkFilter(Capabilities capabilities,
263+
BuildProducer<AdditionalBeanBuildItem> additionalBeans,
263264
BuildProducer<ReflectiveClassBuildItem> reflectiveClass,
264265
BuildProducer<AdditionalIndexedClassesBuildItem> additionalIndexedClassesBuildItem) {
266+
if (!capabilities.isPresent(Capability.SMALLRYE_STORK)) {
267+
return;
268+
}
269+
265270
additionalBeans.produce(AdditionalBeanBuildItem.unremovableOf(StorkClientRequestFilter.class));
266271
additionalIndexedClassesBuildItem
267272
.produce(new AdditionalIndexedClassesBuildItem(StorkClientRequestFilter.class.getName()));

extensions/resteasy-reactive/rest-client/deployment/pom.xml

+5-4
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,6 @@
2424
<groupId>io.quarkus</groupId>
2525
<artifactId>quarkus-rest-client-jaxrs-deployment</artifactId>
2626
</dependency>
27-
<dependency>
28-
<groupId>io.quarkus</groupId>
29-
<artifactId>quarkus-smallrye-stork-deployment</artifactId>
30-
</dependency>
3127
<dependency>
3228
<groupId>io.quarkus</groupId>
3329
<artifactId>quarkus-rest-client-config-deployment</artifactId>
@@ -101,6 +97,11 @@
10197
<artifactId>stork-load-balancer-least-response-time</artifactId>
10298
<scope>test</scope>
10399
</dependency>
100+
<dependency>
101+
<groupId>io.quarkus</groupId>
102+
<artifactId>quarkus-smallrye-stork-deployment</artifactId>
103+
<scope>test</scope>
104+
</dependency>
104105
<dependency>
105106
<groupId>io.smallrye.stork</groupId>
106107
<artifactId>stork-service-discovery-static-list</artifactId>

extensions/resteasy-reactive/rest-client/runtime/pom.xml

-12
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,6 @@
1818
<groupId>io.quarkus</groupId>
1919
<artifactId>quarkus-rest-client-jaxrs</artifactId>
2020
</dependency>
21-
<dependency>
22-
<groupId>io.quarkus</groupId>
23-
<artifactId>quarkus-smallrye-stork</artifactId>
24-
</dependency>
2521
<dependency>
2622
<groupId>io.quarkus</groupId>
2723
<artifactId>quarkus-rest-client-config</artifactId>
@@ -30,14 +26,6 @@
3026
<groupId>io.quarkus</groupId>
3127
<artifactId>quarkus-tls-registry</artifactId>
3228
</dependency>
33-
<dependency>
34-
<groupId>io.smallrye.stork</groupId>
35-
<artifactId>stork-api</artifactId>
36-
</dependency>
37-
<dependency>
38-
<groupId>io.smallrye.stork</groupId>
39-
<artifactId>stork-core</artifactId>
40-
</dependency>
4129
<dependency>
4230
<groupId>org.eclipse.microprofile.rest.client</groupId>
4331
<artifactId>microprofile-rest-client-api</artifactId>

extensions/smallrye-stork/runtime/pom.xml

+5
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@
4141
<plugin>
4242
<groupId>io.quarkus</groupId>
4343
<artifactId>quarkus-extension-maven-plugin</artifactId>
44+
<configuration>
45+
<capabilities>
46+
<provides>io.quarkus.smallrye.stork</provides>
47+
</capabilities>
48+
</configuration>
4449
</plugin>
4550
<plugin>
4651
<artifactId>maven-compiler-plugin</artifactId>

independent-projects/resteasy-reactive/client/runtime/pom.xml

+5
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@
1717
<dependency>
1818
<groupId>io.smallrye.stork</groupId>
1919
<artifactId>stork-core</artifactId>
20+
<optional>true</optional>
21+
</dependency>
22+
<dependency>
23+
<groupId>io.smallrye.stork</groupId>
24+
<artifactId>stork-api</artifactId>
2025
</dependency>
2126
<dependency>
2227
<groupId>io.quarkus.resteasy.reactive</groupId>

independent-projects/resteasy-reactive/client/runtime/src/main/java/org/jboss/resteasy/reactive/client/impl/StorkClientRequestFilter.java

+18-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,25 @@
2020
@Priority(Priorities.AUTHENTICATION)
2121
@Provider
2222
public class StorkClientRequestFilter implements ResteasyReactiveClientRequestFilter {
23+
2324
private static final Logger log = Logger.getLogger(StorkClientRequestFilter.class);
2425

26+
private final Stork stork;
27+
28+
public StorkClientRequestFilter() {
29+
try {
30+
stork = Stork.getInstance();
31+
32+
if (stork == null) {
33+
throw new IllegalStateException(
34+
"Trying to use a StorkClientRequestFilter but the quarkus-smallrye-stork extension is missing, please add the extension.");
35+
}
36+
} catch (Exception e) {
37+
throw new IllegalStateException(
38+
"Trying to use a StorkClientRequestFilter but the quarkus-smallrye-stork extension is missing, please add the extension.");
39+
}
40+
}
41+
2542
@Override
2643
public void filter(ResteasyReactiveClientRequestContext requestContext) {
2744
URI uri = requestContext.getUri();
@@ -34,8 +51,7 @@ public void filter(ResteasyReactiveClientRequestContext requestContext) {
3451
requestContext.suspend();
3552
boolean measureTime = shouldMeasureTime(requestContext.getResponseType());
3653
try {
37-
Stork.getInstance()
38-
.getService(serviceName)
54+
stork.getService(serviceName)
3955
.selectInstanceAndRecordStart(measureTime)
4056
.subscribe()
4157
.with(instance -> {

integration-tests/rest-client-reactive-stork/pom.xml

+17
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@
2222
<groupId>io.quarkus</groupId>
2323
<artifactId>quarkus-rest-client-jackson</artifactId>
2424
</dependency>
25+
<dependency>
26+
<groupId>io.quarkus</groupId>
27+
<artifactId>quarkus-smallrye-stork</artifactId>
28+
</dependency>
2529
<dependency>
2630
<groupId>io.quarkus</groupId>
2731
<artifactId>quarkus-rest-jackson</artifactId>
@@ -93,6 +97,19 @@
9397
</exclusion>
9498
</exclusions>
9599
</dependency>
100+
<dependency>
101+
<groupId>io.quarkus</groupId>
102+
<artifactId>quarkus-smallrye-stork-deployment</artifactId>
103+
<version>${project.version}</version>
104+
<type>pom</type>
105+
<scope>test</scope>
106+
<exclusions>
107+
<exclusion>
108+
<groupId>*</groupId>
109+
<artifactId>*</artifactId>
110+
</exclusion>
111+
</exclusions>
112+
</dependency>
96113
<dependency>
97114
<groupId>io.quarkus</groupId>
98115
<artifactId>quarkus-vertx-http-deployment</artifactId>

0 commit comments

Comments
 (0)