diff --git a/customer-api-consumer/pom.xml b/customer-api-consumer/pom.xml index cb6b680..7d1bfa3 100644 --- a/customer-api-consumer/pom.xml +++ b/customer-api-consumer/pom.xml @@ -50,6 +50,14 @@ io.quarkus quarkus-rest-client-reactive-jsonb + + io.quarkus + quarkus-smallrye-health + + + io.quarkus + quarkus-cache + io.quarkus quarkus-junit5 diff --git a/customer-api-consumer/src/main/java/de/schulung/sample/consumer/CustomerService.java b/customer-api-consumer/src/main/java/de/schulung/sample/consumer/CustomerService.java index f523b73..cb6db42 100644 --- a/customer-api-consumer/src/main/java/de/schulung/sample/consumer/CustomerService.java +++ b/customer-api-consumer/src/main/java/de/schulung/sample/consumer/CustomerService.java @@ -2,6 +2,8 @@ import de.schulung.sample.consumer.client.CustomerApi; import de.schulung.sample.consumer.client.CustomerDto; +import io.quarkus.cache.CacheInvalidateAll; +import io.quarkus.cache.CacheResult; import io.smallrye.mutiny.Uni; import jakarta.enterprise.context.ApplicationScoped; import lombok.RequiredArgsConstructor; @@ -14,7 +16,14 @@ public class CustomerService { private final CustomerApi customerApi; + // https://quarkus.io/guides/cache + + @CacheResult(cacheName = "customers-api-cache") public Uni> getAllCustomers() { // quick'n'dirty without mapping! return customerApi.getAllCustomers(); } + + @CacheInvalidateAll(cacheName = "customers-api-cache") + public void reset(){} + } diff --git a/customer-api-consumer/src/main/java/de/schulung/sample/consumer/CustomersResource.java b/customer-api-consumer/src/main/java/de/schulung/sample/consumer/CustomersResource.java index ca9224c..d22602b 100644 --- a/customer-api-consumer/src/main/java/de/schulung/sample/consumer/CustomersResource.java +++ b/customer-api-consumer/src/main/java/de/schulung/sample/consumer/CustomersResource.java @@ -28,4 +28,12 @@ public Uni getCustomerNames() { ); } + @GET + @Produces(MediaType.TEXT_PLAIN) + @Path("/reset") + public String reset() { + this.service.reset(); + return "Done."; + } + } diff --git a/customer-api-consumer/src/main/resources/application.properties b/customer-api-consumer/src/main/resources/application.properties index 39776b5..625c432 100644 --- a/customer-api-consumer/src/main/resources/application.properties +++ b/customer-api-consumer/src/main/resources/application.properties @@ -1,4 +1,11 @@ %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 \ No newline at end of file +%dev.quarkus.rest-client."customer-api".read-timeout=2000 + +quarkus.cache.caffeine."customers-api-cache".metrics-enabled=true +quarkus.cache.caffeine."customers-api-cache".expire-after-write=60S +quarkus.management.port=9091 +quarkus.management.enabled=true +%dev.quarkus.management.host=localhost +