-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expose Stork Registrars in Quarkus extension + integration test
- Loading branch information
1 parent
fd51d93
commit 03ba2b6
Showing
15 changed files
with
348 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
...lrye-stork/runtime/src/main/java/io/quarkus/stork/StorkServiceRegistrarConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package io.quarkus.stork; | ||
|
||
import java.util.Map; | ||
|
||
import io.quarkus.runtime.annotations.ConfigGroup; | ||
import io.quarkus.runtime.annotations.ConfigItem; | ||
|
||
@ConfigGroup | ||
public class StorkServiceRegistrarConfiguration { | ||
|
||
/** | ||
* Configures service registrar type, e.g. "consul". | ||
* A ServiceRegistrarProvider for the type has to be available | ||
* | ||
*/ | ||
@ConfigItem | ||
public String type; | ||
|
||
/** | ||
* Service Registrar parameters. | ||
* Check the documentation of the selected registrar type for available parameters | ||
* | ||
*/ | ||
@ConfigItem(name = ConfigItem.PARENT) | ||
public Map<String, String> parameters; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
<?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-integration-tests-parent</artifactId> | ||
<groupId>io.quarkus</groupId> | ||
<version>999-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
<artifactId>quarkus-integration-test-smallrye-stork-registration</artifactId> | ||
<name>Quarkus - Integration Tests - Smallrye Stork Registration</name> | ||
|
||
<dependencies> | ||
<!-- Client dependencies --> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-vertx-http</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-rest-client-reactive-jackson</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-resteasy-reactive-jackson</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.smallrye.stork</groupId> | ||
<artifactId>stork-service-discovery-static-list</artifactId> | ||
</dependency> | ||
<!-- Test dependencies --> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-junit5</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.assertj</groupId> | ||
<artifactId>assertj-core</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.rest-assured</groupId> | ||
<artifactId>rest-assured</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.awaitility</groupId> | ||
<artifactId>awaitility</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<!-- Minimal test dependencies to *-deployment artifacts for consistent build order --> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-resteasy-reactive-jackson-deployment</artifactId> | ||
<version>${project.version}</version> | ||
<type>pom</type> | ||
<scope>test</scope> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>*</groupId> | ||
<artifactId>*</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-rest-client-reactive-jackson-deployment</artifactId> | ||
<version>${project.version}</version> | ||
<type>pom</type> | ||
<scope>test</scope> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>*</groupId> | ||
<artifactId>*</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-vertx-http-deployment</artifactId> | ||
<version>${project.version}</version> | ||
<type>pom</type> | ||
<scope>test</scope> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>*</groupId> | ||
<artifactId>*</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<resources> | ||
<resource> | ||
<directory>src/main/resources</directory> | ||
<filtering>true</filtering> | ||
</resource> | ||
</resources> | ||
<plugins> | ||
<plugin> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-maven-plugin</artifactId> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>build</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
<profiles> | ||
<profile> | ||
<id>native-image</id> | ||
<activation> | ||
<property> | ||
<name>native</name> | ||
</property> | ||
</activation> | ||
<properties> | ||
<quarkus.package.type>native</quarkus.package.type> | ||
</properties> | ||
<!-- add some custom config, the rest comes from parent --> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-failsafe-plugin</artifactId> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</profile> | ||
</profiles> | ||
|
||
</project> |
25 changes: 25 additions & 0 deletions
25
...ation-tests/smallrye-stork-registration/src/main/java/org/acme/ClientCallingResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package org.acme; | ||
|
||
import jakarta.ws.rs.GET; | ||
import jakarta.ws.rs.Path; | ||
import jakarta.ws.rs.Produces; | ||
import jakarta.ws.rs.core.MediaType; | ||
|
||
import org.eclipse.microprofile.rest.client.inject.RestClient; | ||
|
||
/** | ||
* A frontend API using our REST Client (which uses Stork to locate and select the service instance on each call). | ||
*/ | ||
@Path("/api") | ||
public class ClientCallingResource { | ||
|
||
@RestClient | ||
MyServiceClient service; | ||
|
||
@GET | ||
@Produces(MediaType.TEXT_PLAIN) | ||
public String invoke() { | ||
return service.get(); | ||
} | ||
|
||
} |
22 changes: 22 additions & 0 deletions
22
integration-tests/smallrye-stork-registration/src/main/java/org/acme/MyServiceClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package org.acme; | ||
|
||
import jakarta.ws.rs.GET; | ||
import jakarta.ws.rs.Produces; | ||
import jakarta.ws.rs.core.MediaType; | ||
|
||
import org.eclipse.microprofile.rest.client.inject.RegisterRestClient; | ||
|
||
/** | ||
* The REST Client interface. | ||
* | ||
* Notice the `baseUri`. It uses `stork://` as URL scheme indicating that the called service uses Stork to locate and | ||
* select the service instance. The `my-service` part is the service name. This is used to configure Stork discovery | ||
* and selection in the `application.properties` file. | ||
*/ | ||
@RegisterRestClient(baseUri = "stork://my-service") | ||
public interface MyServiceClient { | ||
|
||
@GET | ||
@Produces(MediaType.TEXT_PLAIN) | ||
String get(); | ||
} |
27 changes: 27 additions & 0 deletions
27
...ration-tests/smallrye-stork-registration/src/main/java/org/acme/services/BlueService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package org.acme.services; | ||
|
||
import jakarta.enterprise.context.ApplicationScoped; | ||
import jakarta.enterprise.event.Observes; | ||
|
||
import org.eclipse.microprofile.config.inject.ConfigProperty; | ||
|
||
import io.quarkus.runtime.StartupEvent; | ||
import io.vertx.mutiny.core.Vertx; | ||
|
||
@ApplicationScoped | ||
public class BlueService { | ||
|
||
@ConfigProperty(name = "blue-service-port", defaultValue = "9000") | ||
int port; | ||
|
||
/** | ||
* Start an HTTP server for the blue service. | ||
* | ||
* Note: this method is called on a worker thread, and so it is allowed to block. | ||
*/ | ||
public void init(@Observes StartupEvent ev, Vertx vertx) { | ||
vertx.createHttpServer() | ||
.requestHandler(req -> req.response().endAndForget("Hello from Blue!")) | ||
.listenAndAwait(port); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...gration-tests/smallrye-stork-registration/src/main/java/org/acme/services/RedService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
|
||
package org.acme.services; | ||
|
||
import jakarta.enterprise.context.ApplicationScoped; | ||
import jakarta.enterprise.event.Observes; | ||
|
||
import org.eclipse.microprofile.config.inject.ConfigProperty; | ||
|
||
import io.quarkus.runtime.StartupEvent; | ||
import io.vertx.mutiny.core.Vertx; | ||
|
||
@ApplicationScoped | ||
public class RedService { | ||
@ConfigProperty(name = "red-service-port", defaultValue = "9001") | ||
int port; | ||
|
||
/** | ||
* Start an HTTP server for the red service. | ||
* | ||
* Note: this method is called on a worker thread, and so it is allowed to block. | ||
*/ | ||
public void init(@Observes StartupEvent ev, Vertx vertx) { | ||
vertx.createHttpServer() | ||
.requestHandler(req -> req.response().endAndForget("Hello from Red!")) | ||
.listenAndAwait(port); | ||
} | ||
|
||
} |
31 changes: 31 additions & 0 deletions
31
...ation-tests/smallrye-stork-registration/src/main/java/org/acme/services/Registration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package org.acme.services; | ||
|
||
import jakarta.enterprise.context.ApplicationScoped; | ||
import jakarta.enterprise.event.Observes; | ||
|
||
import org.eclipse.microprofile.config.inject.ConfigProperty; | ||
|
||
import io.quarkus.runtime.StartupEvent; | ||
import io.smallrye.stork.Stork; | ||
import io.vertx.mutiny.core.Vertx; | ||
|
||
@ApplicationScoped | ||
public class Registration { | ||
|
||
@ConfigProperty(name = "red-service-port", defaultValue = "9000") | ||
int red; | ||
@ConfigProperty(name = "blue-service-port", defaultValue = "9001") | ||
int blue; | ||
|
||
/** | ||
* Register our two services using static list. | ||
* | ||
* Note: this method is called on a worker thread, and so it is allowed to block. | ||
*/ | ||
public void init(@Observes StartupEvent ev, Vertx vertx) { | ||
Stork.getInstance().getService("my-service").getServiceRegistrar().registerServiceInstance("my-service", "localhost", | ||
red); | ||
Stork.getInstance().getService("my-service").getServiceRegistrar().registerServiceInstance("my-service", "localhost", | ||
blue); | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
integration-tests/smallrye-stork-registration/src/main/resources/application.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
quarkus.stork.my-service.service-discovery.type=static | ||
|
||
quarkus.stork.my-service.service-registrar.type=static |
8 changes: 8 additions & 0 deletions
8
...ion-tests/smallrye-stork-registration/src/test/java/org/acme/ClientCallingResourceIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package org.acme; | ||
|
||
import io.quarkus.test.junit.QuarkusIntegrationTest; | ||
|
||
@QuarkusIntegrationTest | ||
public class ClientCallingResourceIT extends ClientCallingResourceTest { | ||
|
||
} |
24 changes: 24 additions & 0 deletions
24
...n-tests/smallrye-stork-registration/src/test/java/org/acme/ClientCallingResourceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package org.acme; | ||
|
||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import io.quarkus.test.junit.QuarkusTest; | ||
import io.restassured.RestAssured; | ||
|
||
@QuarkusTest | ||
public class ClientCallingResourceTest { | ||
|
||
@Test | ||
public void test() { | ||
Set<String> bodies = new HashSet<>(); | ||
for (int i = 0; i < 10; i++) { | ||
bodies.add(RestAssured.get("/api").then().statusCode(200).extract().body().asString()); | ||
} | ||
Assertions.assertEquals(2, bodies.size()); | ||
} | ||
|
||
} |