Skip to content

Commit

Permalink
Add baremetal stork/consul scenario
Browse files Browse the repository at this point in the history
  • Loading branch information
pablo gonzalez granados committed Mar 16, 2022
1 parent 1832cb7 commit b8544ac
Show file tree
Hide file tree
Showing 11 changed files with 447 additions and 0 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,18 @@ this.router.get("/secured")
* authZ::authorize: custom AuthZ(authorization) provider.
* secure.helloWorld(rc): actual http endpoint (Rest layer).

### Service-discovery/stork-consul

Verifies Stork-consul integration in order to provide service discovering and round-robin load balancing between services

`StorkServiceDiscoveryIT` scenario deploys four services:
* Pung: is a simple endpoint that returns "pung" as a string
* Pong: is a simple endpoint that returns "pong" as a string
* PongReplica: is a "Pong service" replica, that is deployed in another physical service
* Ping: is the main client microservice that will use `pung` and `pong` (Pong and PongReplica) services. The service
discovery will be done by Stork, and the request dispatching between "pong" services is going to be done by Stork load balancer.



### `monitoring/microprofile`

Expand Down
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@
<module>docker-build</module>
<module>javaee-like-getting-started</module>
<module>scaling</module>
<module>service-discovery/stork-consul</module>
<module>lifecycle-application</module>
<module>external-applications</module>
<module>scheduling/quartz</module>
Expand Down
63 changes: 63 additions & 0 deletions service-discovery/stork-consul/pom.xml
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>
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();
}
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();
}
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);
}
}
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);
}
}
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);
}
}
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");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# application properties should be here
Loading

0 comments on commit b8544ac

Please sign in to comment.