-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
pablo gonzalez granados
committed
Mar 16, 2022
1 parent
1832cb7
commit b8544ac
Showing
11 changed files
with
447 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>io.quarkus.ts.qe</groupId> | ||
<artifactId>parent</artifactId> | ||
<version>1.0.0-SNAPSHOT</version> | ||
<relativePath>../..</relativePath> | ||
</parent> | ||
<artifactId>stork</artifactId> | ||
<packaging>jar</packaging> | ||
<name>Quarkus QE TS: stork-consul</name> | ||
<dependencies> | ||
<dependency> | ||
<groupId>io.smallrye.stork</groupId> | ||
<artifactId>stork-service-discovery-consul</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.smallrye.reactive</groupId> | ||
<artifactId>smallrye-mutiny-vertx-consul-client</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-reactive-routes</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-rest-client-reactive</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus.qe</groupId> | ||
<artifactId>quarkus-test-service-consul</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
<profiles> | ||
<!-- Skipped on Windows as does not support Linux Containers / Testcontainers --> | ||
<profile> | ||
<id>skip-tests-on-windows</id> | ||
<activation> | ||
<os> | ||
<family>windows</family> | ||
</os> | ||
</activation> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<configuration> | ||
<skip>true</skip> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-failsafe-plugin</artifactId> | ||
<configuration> | ||
<skip>true</skip> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</profile> | ||
</profiles> | ||
</project> |
19 changes: 19 additions & 0 deletions
19
service-discovery/stork-consul/src/main/java/io/quarkus/ts/stork/MyBackendPongProxy.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,19 @@ | ||
package io.quarkus.ts.stork; | ||
|
||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.Produces; | ||
import javax.ws.rs.core.MediaType; | ||
|
||
import org.eclipse.microprofile.rest.client.inject.RegisterRestClient; | ||
|
||
import io.smallrye.mutiny.Uni; | ||
|
||
@Path("/pong") | ||
@RegisterRestClient(baseUri = "stork://pong") | ||
public interface MyBackendPongProxy { | ||
@GET | ||
@Produces(MediaType.TEXT_PLAIN) | ||
@Path("/") | ||
Uni<String> get(); | ||
} |
19 changes: 19 additions & 0 deletions
19
service-discovery/stork-consul/src/main/java/io/quarkus/ts/stork/MyBackendPungProxy.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,19 @@ | ||
package io.quarkus.ts.stork; | ||
|
||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.Produces; | ||
import javax.ws.rs.core.MediaType; | ||
|
||
import org.eclipse.microprofile.rest.client.inject.RegisterRestClient; | ||
|
||
import io.smallrye.mutiny.Uni; | ||
|
||
@Path("/pung") | ||
@RegisterRestClient(baseUri = "stork://pung") | ||
public interface MyBackendPungProxy { | ||
@GET | ||
@Produces(MediaType.TEXT_PLAIN) | ||
@Path("/") | ||
Uni<String> get(); | ||
} |
37 changes: 37 additions & 0 deletions
37
service-discovery/stork-consul/src/main/java/io/quarkus/ts/stork/PingResource.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,37 @@ | ||
package io.quarkus.ts.stork; | ||
|
||
import javax.ws.rs.WebApplicationException; | ||
import javax.ws.rs.core.MediaType; | ||
|
||
import org.eclipse.microprofile.rest.client.inject.RestClient; | ||
|
||
import io.quarkus.vertx.web.Route; | ||
import io.quarkus.vertx.web.RouteBase; | ||
import io.smallrye.mutiny.Uni; | ||
import io.vertx.ext.web.RoutingContext; | ||
|
||
@RouteBase(path = "/ping", produces = MediaType.TEXT_PLAIN) | ||
public class PingResource { | ||
|
||
@RestClient | ||
MyBackendPongProxy pongService; | ||
|
||
@RestClient | ||
MyBackendPungProxy pungService; | ||
|
||
@Route(methods = Route.HttpMethod.GET, path = "/pung") | ||
public Uni<String> pung(RoutingContext context) { | ||
return formatResponse(pungService.get()); | ||
} | ||
|
||
@Route(methods = Route.HttpMethod.GET, path = "/pong") | ||
public Uni<String> pong(RoutingContext context) { | ||
return formatResponse(pongService.get()); | ||
} | ||
|
||
private Uni<String> formatResponse(Uni<String> response) { | ||
return response | ||
.onFailure().transform(error -> new WebApplicationException(error.getMessage())) | ||
.map(resp -> "ping-" + resp); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
service-discovery/stork-consul/src/main/java/io/quarkus/ts/stork/PongReplicaResource.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,46 @@ | ||
package io.quarkus.ts.stork; | ||
|
||
import static io.quarkus.ts.stork.PongResource.PONG_SERVICE_NAME; | ||
|
||
import javax.enterprise.event.Observes; | ||
import javax.ws.rs.core.MediaType; | ||
|
||
import org.eclipse.microprofile.config.inject.ConfigProperty; | ||
|
||
import io.quarkus.runtime.StartupEvent; | ||
import io.quarkus.vertx.web.Route; | ||
import io.quarkus.vertx.web.RouteBase; | ||
import io.smallrye.mutiny.Uni; | ||
import io.vertx.ext.consul.ConsulClientOptions; | ||
import io.vertx.ext.consul.ServiceOptions; | ||
import io.vertx.mutiny.core.Vertx; | ||
import io.vertx.mutiny.ext.consul.ConsulClient; | ||
|
||
@RouteBase(path = "/pong", produces = MediaType.TEXT_PLAIN) | ||
public class PongReplicaResource { | ||
|
||
public static final String DEFAULT_PONG_REPLICA_RESPONSE = "pongReplica"; | ||
|
||
@ConfigProperty(name = "stork.pong-replica.service-discovery.consul-host") | ||
String host; | ||
@ConfigProperty(name = "stork.pong-replica.service-discovery.consul-port") | ||
String port; | ||
@ConfigProperty(name = "pong-replica-service-port") | ||
String pongPort; | ||
@ConfigProperty(name = "pong-replica-service-host") | ||
String pongHost; | ||
|
||
public void init(@Observes StartupEvent ev, Vertx vertx) { | ||
ConsulClient client = ConsulClient.create(vertx, | ||
new ConsulClientOptions().setHost(host).setPort(Integer.parseInt(port))); | ||
|
||
client.registerServiceAndAwait( | ||
new ServiceOptions().setPort(Integer.parseInt(pongPort)).setAddress(pongHost).setName(PONG_SERVICE_NAME) | ||
.setId("pongReplica")); | ||
} | ||
|
||
@Route(path = "/", methods = Route.HttpMethod.GET) | ||
public Uni<String> pong() { | ||
return Uni.createFrom().item(DEFAULT_PONG_REPLICA_RESPONSE); | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
service-discovery/stork-consul/src/main/java/io/quarkus/ts/stork/PongResource.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,45 @@ | ||
package io.quarkus.ts.stork; | ||
|
||
import javax.enterprise.event.Observes; | ||
import javax.ws.rs.core.MediaType; | ||
|
||
import org.eclipse.microprofile.config.inject.ConfigProperty; | ||
|
||
import io.quarkus.runtime.StartupEvent; | ||
import io.quarkus.vertx.web.Route; | ||
import io.quarkus.vertx.web.RouteBase; | ||
import io.smallrye.mutiny.Uni; | ||
import io.vertx.ext.consul.ConsulClientOptions; | ||
import io.vertx.ext.consul.ServiceOptions; | ||
import io.vertx.mutiny.core.Vertx; | ||
import io.vertx.mutiny.ext.consul.ConsulClient; | ||
|
||
@RouteBase(path = "/pong", produces = MediaType.TEXT_PLAIN) | ||
public class PongResource { | ||
|
||
public static final String PONG_SERVICE_NAME = "pong"; | ||
public static final String DEFAULT_PONG_RESPONSE = "pong"; | ||
|
||
@ConfigProperty(name = "stork.pong.service-discovery.consul-host") | ||
String host; | ||
@ConfigProperty(name = "stork.pong.service-discovery.consul-port") | ||
String port; | ||
@ConfigProperty(name = "pong-service-port") | ||
String pongPort; | ||
@ConfigProperty(name = "pong-service-host") | ||
String pongHost; | ||
|
||
public void init(@Observes StartupEvent ev, Vertx vertx) { | ||
ConsulClient client = ConsulClient.create(vertx, | ||
new ConsulClientOptions().setHost(host).setPort(Integer.parseInt(port))); | ||
|
||
client.registerServiceAndAwait( | ||
new ServiceOptions().setPort(Integer.parseInt(pongPort)).setAddress(pongHost).setName(PONG_SERVICE_NAME) | ||
.setId("pong")); | ||
} | ||
|
||
@Route(path = "/", methods = Route.HttpMethod.GET) | ||
public Uni<String> pong() { | ||
return Uni.createFrom().item(DEFAULT_PONG_RESPONSE); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
service-discovery/stork-consul/src/main/java/io/quarkus/ts/stork/PungResource.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,41 @@ | ||
package io.quarkus.ts.stork; | ||
|
||
import javax.enterprise.event.Observes; | ||
import javax.ws.rs.core.MediaType; | ||
|
||
import org.eclipse.microprofile.config.inject.ConfigProperty; | ||
|
||
import io.quarkus.runtime.StartupEvent; | ||
import io.quarkus.vertx.web.Route; | ||
import io.quarkus.vertx.web.RouteBase; | ||
import io.smallrye.mutiny.Uni; | ||
import io.vertx.ext.consul.ConsulClientOptions; | ||
import io.vertx.ext.consul.ServiceOptions; | ||
import io.vertx.mutiny.core.Vertx; | ||
import io.vertx.mutiny.ext.consul.ConsulClient; | ||
|
||
@RouteBase(path = "/pung", produces = MediaType.TEXT_PLAIN) | ||
public class PungResource { | ||
|
||
@ConfigProperty(name = "stork.pung.service-discovery.consul-host") | ||
String host; | ||
@ConfigProperty(name = "stork.pung.service-discovery.consul-port") | ||
String port; | ||
@ConfigProperty(name = "pung-service-port") | ||
String pungPort; | ||
@ConfigProperty(name = "pung-service-host") | ||
String pungHost; | ||
|
||
public void init(@Observes StartupEvent ev, Vertx vertx) { | ||
ConsulClient client = ConsulClient.create(vertx, | ||
new ConsulClientOptions().setHost(host).setPort(Integer.parseInt(port))); | ||
|
||
client.registerServiceAndAwait( | ||
new ServiceOptions().setPort(Integer.parseInt(pungPort)).setAddress(pungHost).setName("pung").setId("pung")); | ||
} | ||
|
||
@Route(path = "/", methods = Route.HttpMethod.GET) | ||
public Uni<String> pung() { | ||
return Uni.createFrom().item("pung"); | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
service-discovery/stork-consul/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 @@ | ||
# application properties should be here |
Oops, something went wrong.