Skip to content
This repository has been archived by the owner on Jul 26, 2024. It is now read-only.

Commit

Permalink
Merge pull request #23 from ralf-ueberfuhr-ars/feature/customer-api-c…
Browse files Browse the repository at this point in the history
…onsumer

Introduce REST API consumer (reactive)
  • Loading branch information
ralf-ueberfuhr-ars authored Jun 21, 2024
2 parents 63f0411 + 3d9bfc2 commit eff0d09
Show file tree
Hide file tree
Showing 9 changed files with 294 additions and 1 deletion.
7 changes: 6 additions & 1 deletion .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ on:
- "main"
paths:
- "customer-api-provider/**"
- "customer-api-consumer/**"
- ".github/**"
pull_request:
branches:
- "main"
paths:
- "customer-api-provider/**"
- "customer-api-consumer/**"
- ".github/**"

jobs:
Expand All @@ -27,6 +29,9 @@ jobs:
java-version: '21'
distribution: 'temurin'
cache: maven
- name: Build with Maven
- name: Build API Provider with Maven
working-directory: customer-api-provider
run: mvn -B package --file pom.xml
- name: Build API Consumer with Maven
working-directory: customer-api-consumer
run: mvn -B package --file pom.xml
153 changes: 153 additions & 0 deletions customer-api-consumer/pom.xml
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>
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);
}

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

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

}
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;

}
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;

}
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

0 comments on commit eff0d09

Please sign in to comment.