This repository has been archived by the owner on Jul 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
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
Ralf Ueberfuhr
committed
Jun 20, 2024
1 parent
09a3fc9
commit 107866b
Showing
9 changed files
with
294 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
<?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"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>de.schulung.quarkus</groupId> | ||
<artifactId>customer-api-consumer</artifactId> | ||
<version>1.0.0-SNAPSHOT</version> | ||
|
||
<properties> | ||
<compiler-plugin.version>3.12.1</compiler-plugin.version> | ||
<maven.compiler.release>21</maven.compiler.release> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> | ||
<quarkus.platform.artifact-id>quarkus-bom</quarkus.platform.artifact-id> | ||
<quarkus.platform.group-id>io.quarkus.platform</quarkus.platform.group-id> | ||
<quarkus.platform.version>3.11.2</quarkus.platform.version> | ||
<skipITs>true</skipITs> | ||
<surefire-plugin.version>3.2.5</surefire-plugin.version> | ||
<lombok.version>1.18.32</lombok.version> | ||
</properties> | ||
|
||
<dependencyManagement> | ||
<dependencies> | ||
<dependency> | ||
<groupId>io.quarkus.platform</groupId> | ||
<artifactId>quarkus-bom</artifactId> | ||
<version>${quarkus.platform.version}</version> | ||
<type>pom</type> | ||
<scope>import</scope> | ||
</dependency> | ||
</dependencies> | ||
</dependencyManagement> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.projectlombok</groupId> | ||
<artifactId>lombok</artifactId> | ||
<version>${lombok.version}</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-arc</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-resteasy-reactive</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-rest-client-reactive-jsonb</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-junit5</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-junit5-mockito</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<pluginManagement> | ||
<plugins> | ||
<plugin> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>${compiler-plugin.version}</version> | ||
<configuration> | ||
<annotationProcessorPaths> | ||
<path> | ||
<groupId>org.projectlombok</groupId> | ||
<artifactId>lombok</artifactId> | ||
<version>${lombok.version}</version> | ||
</path> | ||
</annotationProcessorPaths> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</pluginManagement> | ||
<plugins> | ||
<plugin> | ||
<groupId>${quarkus.platform.group-id}</groupId> | ||
<artifactId>quarkus-maven-plugin</artifactId> | ||
<version>${quarkus.platform.version}</version> | ||
<extensions>true</extensions> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>build</goal> | ||
<goal>generate-code</goal> | ||
<goal>generate-code-tests</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<configuration> | ||
<compilerArgs> | ||
<arg>-parameters</arg> | ||
</compilerArgs> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<version>${surefire-plugin.version}</version> | ||
<configuration> | ||
<systemPropertyVariables> | ||
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager> | ||
<maven.home>${maven.home}</maven.home> | ||
</systemPropertyVariables> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-failsafe-plugin</artifactId> | ||
<version>${surefire-plugin.version}</version> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>integration-test</goal> | ||
<goal>verify</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
<configuration> | ||
<systemPropertyVariables> | ||
<native.image.path>${project.build.directory}/${project.build.finalName}-runner</native.image.path> | ||
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager> | ||
<maven.home>${maven.home}</maven.home> | ||
</systemPropertyVariables> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
<profiles> | ||
<profile> | ||
<id>native</id> | ||
<activation> | ||
<property> | ||
<name>native</name> | ||
</property> | ||
</activation> | ||
<properties> | ||
<skipITs>false</skipITs> | ||
<quarkus.native.enabled>true</quarkus.native.enabled> | ||
</properties> | ||
</profile> | ||
</profiles> | ||
</project> |
13 changes: 13 additions & 0 deletions
13
...r-api-consumer/src/main/java/de/schulung/sample/consumer/CustomerConsumerApplication.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,13 @@ | ||
package de.schulung.sample.consumer; | ||
|
||
import io.quarkus.runtime.Quarkus; | ||
import io.quarkus.runtime.annotations.QuarkusMain; | ||
|
||
@QuarkusMain | ||
public class CustomerConsumerApplication { | ||
|
||
public static void main(String[] args) { | ||
Quarkus.run(args); | ||
} | ||
|
||
} |
20 changes: 20 additions & 0 deletions
20
customer-api-consumer/src/main/java/de/schulung/sample/consumer/CustomerService.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,20 @@ | ||
package de.schulung.sample.consumer; | ||
|
||
import de.schulung.sample.consumer.client.CustomerApi; | ||
import de.schulung.sample.consumer.client.CustomerDto; | ||
import io.smallrye.mutiny.Uni; | ||
import jakarta.enterprise.context.ApplicationScoped; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
import java.util.Collection; | ||
|
||
@ApplicationScoped | ||
@RequiredArgsConstructor | ||
public class CustomerService { | ||
|
||
private final CustomerApi customerApi; | ||
|
||
public Uni<Collection<CustomerDto>> getAllCustomers() { // quick'n'dirty without mapping! | ||
return customerApi.getAllCustomers(); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
customer-api-consumer/src/main/java/de/schulung/sample/consumer/CustomersResource.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 de.schulung.sample.consumer; | ||
|
||
import de.schulung.sample.consumer.client.CustomerDto; | ||
import io.smallrye.mutiny.Uni; | ||
import jakarta.ws.rs.GET; | ||
import jakarta.ws.rs.Path; | ||
import jakarta.ws.rs.Produces; | ||
import jakarta.ws.rs.core.MediaType; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
import java.util.stream.Collectors; | ||
|
||
@RequiredArgsConstructor | ||
@Path("/customers") | ||
public class CustomersResource { | ||
|
||
private final CustomerService service; | ||
|
||
@GET | ||
@Produces(MediaType.TEXT_PLAIN) | ||
public Uni<String> getCustomerNames() { | ||
return this.service | ||
.getAllCustomers() | ||
.map(list -> list | ||
.stream() | ||
.map(CustomerDto::getName) | ||
.collect(Collectors.joining("\n")) | ||
); | ||
} | ||
|
||
} |
22 changes: 22 additions & 0 deletions
22
customer-api-consumer/src/main/java/de/schulung/sample/consumer/client/CustomerApi.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 de.schulung.sample.consumer.client; | ||
|
||
import io.smallrye.mutiny.Uni; | ||
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.RegisterRestClient; | ||
|
||
import java.util.Collection; | ||
|
||
@RegisterRestClient(configKey = "customer-api") | ||
@Path("/customers") | ||
public interface CustomerApi { | ||
|
||
// https://quarkus.io/guides/rest-client | ||
|
||
@GET | ||
@Produces(MediaType.APPLICATION_JSON) | ||
Uni<Collection<CustomerDto>> getAllCustomers(); | ||
|
||
} |
19 changes: 19 additions & 0 deletions
19
...er-api-consumer/src/main/java/de/schulung/sample/consumer/client/CustomerApiProvider.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 de.schulung.sample.consumer.client; | ||
|
||
import jakarta.enterprise.context.ApplicationScoped; | ||
import jakarta.enterprise.inject.Default; | ||
import jakarta.enterprise.inject.Produces; | ||
import lombok.Getter; | ||
import org.eclipse.microprofile.rest.client.inject.RestClient; | ||
|
||
@ApplicationScoped | ||
public class CustomerApiProvider { | ||
|
||
@RestClient | ||
@Getter(onMethod_ = { | ||
@Produces, | ||
@Default | ||
}) | ||
CustomerApi customerApi; | ||
|
||
} |
26 changes: 26 additions & 0 deletions
26
customer-api-consumer/src/main/java/de/schulung/sample/consumer/client/CustomerDto.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,26 @@ | ||
package de.schulung.sample.consumer.client; | ||
|
||
import jakarta.json.bind.annotation.JsonbTransient; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
|
||
import java.time.LocalDate; | ||
import java.util.UUID; | ||
|
||
@Getter | ||
@Setter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class CustomerDto { | ||
|
||
// readonly property | ||
@Setter(onMethod_ = @JsonbTransient) | ||
private UUID uuid; | ||
private String name; | ||
//@JsonbProperty("birth_date") | ||
private LocalDate birthDate; | ||
private String state; | ||
|
||
} |
4 changes: 4 additions & 0 deletions
4
customer-api-consumer/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,4 @@ | ||
%dev.quarkus.http.port=8081 | ||
%dev.quarkus.rest-client."customer-api".url=http://localhost:8080 | ||
quarkus.rest-client."customer-api".connect-timeout=2000 | ||
%dev.quarkus.rest-client."customer-api".read-timeout=2000 |