Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose Stork Registars in Quarkus extension + integration test #34372

Merged
merged 2 commits into from
Jul 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bom/application/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
<smallrye-reactive-types-converter.version>3.0.0</smallrye-reactive-types-converter.version>
<smallrye-mutiny-vertx-binding.version>3.5.0</smallrye-mutiny-vertx-binding.version>
<smallrye-reactive-messaging.version>4.7.0</smallrye-reactive-messaging.version>
<smallrye-stork.version>2.2.0</smallrye-stork.version>
<smallrye-stork.version>2.3.0</smallrye-stork.version>
<jakarta.activation.version>2.1.2</jakarta.activation.version>
<jakarta.annotation-api.version>2.1.1</jakarta.annotation-api.version>
<jakarta.enterprise.cdi-api.version>4.0.1</jakarta.enterprise.cdi-api.version>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
package io.quarkus.stork;

import java.util.Optional;

import io.quarkus.runtime.annotations.ConfigGroup;
import io.quarkus.runtime.annotations.ConfigItem;

@ConfigGroup
public class ServiceConfiguration {
public interface ServiceConfiguration {
/**
* ServiceDiscovery configuration for the service
*/
@ConfigItem
public StorkServiceDiscoveryConfiguration serviceDiscovery;
StorkServiceDiscoveryConfiguration serviceDiscovery();

/**
* LoadBalancer configuration for the service
*/
@ConfigItem
public StorkLoadBalancerConfiguration loadBalancer;
StorkLoadBalancerConfiguration loadBalancer();

/**
* ServiceRegistrar configuration for the service
*/
Optional<StorkServiceRegistrarConfiguration> serviceRegistrar();
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,23 @@ public class StorkConfigUtil {

public static List<ServiceConfig> toStorkServiceConfig(StorkConfiguration storkConfiguration) {
List<ServiceConfig> storkServicesConfigs = new ArrayList<>();
Set<String> servicesConfigs = storkConfiguration.serviceConfiguration.keySet();
Set<String> servicesConfigs = storkConfiguration.serviceConfiguration().keySet();
SimpleServiceConfig.Builder builder = new SimpleServiceConfig.Builder();
for (String serviceName : servicesConfigs) {
builder.setServiceName(serviceName);
ServiceConfiguration serviceConfiguration = storkConfiguration.serviceConfiguration.get(serviceName);
ServiceConfiguration serviceConfiguration = storkConfiguration.serviceConfiguration().get(serviceName);
SimpleServiceConfig.SimpleServiceDiscoveryConfig storkServiceDiscoveryConfig = new SimpleServiceConfig.SimpleServiceDiscoveryConfig(
serviceConfiguration.serviceDiscovery.type, serviceConfiguration.serviceDiscovery.params);
serviceConfiguration.serviceDiscovery().type(), serviceConfiguration.serviceDiscovery().params());
builder = builder.setServiceDiscovery(storkServiceDiscoveryConfig);
SimpleServiceConfig.SimpleLoadBalancerConfig loadBalancerConfig = new SimpleServiceConfig.SimpleLoadBalancerConfig(
serviceConfiguration.loadBalancer.type, serviceConfiguration.loadBalancer.parameters);
serviceConfiguration.loadBalancer().type(), serviceConfiguration.loadBalancer().parameters());
builder.setLoadBalancer(loadBalancerConfig);
if (serviceConfiguration.serviceRegistrar().isPresent()) {
SimpleServiceConfig.SimpleServiceRegistrarConfig serviceRegistrarConfig = new SimpleServiceConfig.SimpleServiceRegistrarConfig(
serviceConfiguration.serviceRegistrar().get().type(),
serviceConfiguration.serviceRegistrar().get().parameters());
builder.setServiceRegistrar(serviceRegistrarConfig);
}
storkServicesConfigs.add(builder.build());
}
return storkServicesConfigs;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,24 @@

import io.quarkus.runtime.annotations.ConfigDocMapKey;
import io.quarkus.runtime.annotations.ConfigDocSection;
import io.quarkus.runtime.annotations.ConfigItem;
import io.quarkus.runtime.annotations.ConfigPhase;
import io.quarkus.runtime.annotations.ConfigRoot;
import io.smallrye.config.ConfigMapping;
import io.smallrye.config.WithParentName;

/**
* Stork configuration root.
*/
@ConfigMapping(prefix = "quarkus.stork")
@ConfigRoot(phase = ConfigPhase.RUN_TIME)
public class StorkConfiguration {
public interface StorkConfiguration {

/**
* ServiceDiscovery configuration for the service
* Configuration for the service
*/
@ConfigItem(name = ConfigItem.PARENT)
@WithParentName
@ConfigDocSection
@ConfigDocMapKey("service-name")
public Map<String, ServiceConfiguration> serviceConfiguration;
Map<String, ServiceConfiguration> serviceConfiguration();

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,26 @@
import java.util.Map;

import io.quarkus.runtime.annotations.ConfigGroup;
import io.quarkus.runtime.annotations.ConfigItem;
import io.smallrye.config.WithDefault;
import io.smallrye.config.WithParentName;

@ConfigGroup
public class StorkLoadBalancerConfiguration {
public interface StorkLoadBalancerConfiguration {

/**
* Configures load balancer type, e.g. "round-robin".
* A LoadBalancerProvider for the type has to be available
*
*/
@ConfigItem(defaultValue = "round-robin")
public String type;
@WithDefault(value = "round-robin")
String type();

/**
* Load Balancer parameters.
* Check the documentation of the selected load balancer type for available parameters
*
*/
@ConfigItem(name = ConfigItem.PARENT)
public Map<String, String> parameters;
@WithParentName
Map<String, String> parameters();

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,24 @@
import java.util.Map;

import io.quarkus.runtime.annotations.ConfigGroup;
import io.quarkus.runtime.annotations.ConfigItem;
import io.smallrye.config.WithParentName;

@ConfigGroup
public class StorkServiceDiscoveryConfiguration {
public interface StorkServiceDiscoveryConfiguration {

/**
* Configures the service discovery type, e.g. "consul".
* ServiceDiscoveryProvider for the type has to be available
*
*/
@ConfigItem
public String type;
String type();

/**
* ServiceDiscovery parameters.
* Check the documentation of the selected service discovery type for available parameters.
*
*/
@ConfigItem(name = ConfigItem.PARENT)
public Map<String, String> params;
@WithParentName
Map<String, String> params();

}
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.smallrye.config.WithParentName;

@ConfigGroup
public interface StorkServiceRegistrarConfiguration {

/**
* Configures service registrar type, e.g. "consul".
* A ServiceRegistrarProvider for the type has to be available
*
*/
String type();

/**
* Service Registrar parameters.
* Check the documentation of the selected registrar type for available parameters
*
*/
// @ConfigItem(name = ConfigItem.PARENT)
@WithParentName
Map<String, String> parameters();

}
2 changes: 1 addition & 1 deletion independent-projects/resteasy-reactive/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
<rest-assured.version>5.3.0</rest-assured.version>
<commons-logging-jboss-logging.version>1.0.0.Final</commons-logging-jboss-logging.version>
<jackson-bom.version>2.15.2</jackson-bom.version>
<smallrye-stork.version>2.1.0</smallrye-stork.version>
<smallrye-stork.version>2.3.0</smallrye-stork.version>
<jakarta.validation-api.version>3.0.2</jakarta.validation-api.version>
<yasson.version>3.0.3</yasson.version>
<jakarta.json.bind-api.version>3.0.0</jakarta.json.bind-api.version>
Expand Down
1 change: 1 addition & 0 deletions integration-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@
<module>smallrye-graphql</module>
<module>smallrye-graphql-client</module>
<module>smallrye-opentracing</module>
<module>smallrye-stork-registration</module>
<module>jpa-without-entity</module>
<module>quartz</module>
<module>redis-client</module>
Expand Down
141 changes: 141 additions & 0 deletions integration-tests/smallrye-stork-registration/pom.xml
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>
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();
}

}
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();
}
Loading