diff --git a/README.md b/README.md
index 5276c8a..1780d6f 100644
--- a/README.md
+++ b/README.md
@@ -63,7 +63,7 @@ Steps:
- Add a configuration property inside you `application.properties` file: `greeting=World`
- Modify `BookmarkResource` to read this configuration property and log it at startup:
- Use `@ConfigProperty` to inject the property inside a `greeting` variable.
- - Create a `@PostConstruct` method that log it via `log.info("Hello {}", greeting)` using [SLFJ](https://www.slf4j.org/).
+ - Create a `@PostConstruct` method that log it via `LOGGER.infof("Hello %s", greeting)` using [Jboss logging](https://docs.jboss.org/jbosslogging/latest/org/jboss/logging/Logger.html).
- Test using `mvn quarkus:dev` you should see `Hello World` in the console.
- Add a new line to `application.properties` file: `%dev.greeting=Dev` this is an override of the same property for the dev profile.
- Test using `mvn quarkus:dev` you should see `Hello Dev` in the console.
diff --git a/bookmark-message-consumer/pom.xml b/bookmark-message-consumer/pom.xml
index c51bd3d..d458b00 100644
--- a/bookmark-message-consumer/pom.xml
+++ b/bookmark-message-consumer/pom.xml
@@ -9,7 +9,7 @@
2.22.0
1.8
1.8
- 0.22.0
+ 1.0.1.Final
UTF-8
UTF-8
diff --git a/bookmark-message-consumer/src/main/java/fr/loicmathieu/bookmarkit/BookmarkConsumer.java b/bookmark-message-consumer/src/main/java/fr/loicmathieu/bookmarkit/BookmarkConsumer.java
index 9b8b758..d74c03e 100644
--- a/bookmark-message-consumer/src/main/java/fr/loicmathieu/bookmarkit/BookmarkConsumer.java
+++ b/bookmark-message-consumer/src/main/java/fr/loicmathieu/bookmarkit/BookmarkConsumer.java
@@ -1,18 +1,17 @@
package fr.loicmathieu.bookmarkit;
import org.eclipse.microprofile.reactive.messaging.Incoming;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import org.jboss.logging.Logger;
import javax.enterprise.context.ApplicationScoped;
@ApplicationScoped
public class BookmarkConsumer {
- private final Logger log = LoggerFactory.getLogger(BookmarkConsumer.class);
+ private static final Logger LOG = Logger.getLogger(BookmarkConsumer.class);
@Incoming("bookmarks")
public void process(String bookmark) {
- log.info("Indexing a bookmark: {}", bookmark);
+ LOG.infof("Indexing a bookmark: %s", bookmark);
}
}
diff --git a/bookmark-message-consumer/src/test/java/fr/loicmathieu/bookmarkit/NativeBookmarkConsumerIT.java b/bookmark-message-consumer/src/test/java/fr/loicmathieu/bookmarkit/NativeBookmarkConsumerIT.java
deleted file mode 100644
index c92dec8..0000000
--- a/bookmark-message-consumer/src/test/java/fr/loicmathieu/bookmarkit/NativeBookmarkConsumerIT.java
+++ /dev/null
@@ -1,9 +0,0 @@
-package fr.loicmathieu.bookmarkit;
-
-import io.quarkus.test.junit.SubstrateTest;
-
-@SubstrateTest
-public class NativeBookmarkConsumerIT extends BookmarkConsumerTest {
-
- // Execute the same tests but in native mode.
-}
diff --git a/bookmark-message-consumer/target/classes/application.properties b/bookmark-message-consumer/target/classes/application.properties
deleted file mode 100644
index 9dca708..0000000
--- a/bookmark-message-consumer/target/classes/application.properties
+++ /dev/null
@@ -1,8 +0,0 @@
-quarkus.http.port=8081
-
-# Configures the AMQP broker credentials.
-amqp-username=quarkus
-amqp-password=quarkus
-# Configure the AMQP connector to read from the `prices` queue
-mp.messaging.incoming.bookmarks.connector=smallrye-amqp
-mp.messaging.incoming.bookmarks.durable=true
\ No newline at end of file
diff --git a/bookmark-message-consumer/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst b/bookmark-message-consumer/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst
deleted file mode 100644
index 9bfd80e..0000000
--- a/bookmark-message-consumer/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst
+++ /dev/null
@@ -1 +0,0 @@
-fr/loicmathieu/bookmarkit/BookmarkConsumer.class
diff --git a/bookmark-service/pom.xml b/bookmark-service/pom.xml
index eb4fd31..5f1bb6a 100644
--- a/bookmark-service/pom.xml
+++ b/bookmark-service/pom.xml
@@ -9,7 +9,7 @@
2.22.0
1.8
1.8
- 0.26.1
+ 1.0.1.Final
UTF-8
UTF-8
@@ -42,29 +42,32 @@
io.quarkus
quarkus-smallrye-health
+
io.quarkus
quarkus-jdbc-postgresql
+
+
io.quarkus
quarkus-smallrye-metrics
-
-
-
-
+
+ io.quarkus
+ quarkus-smallrye-reactive-messaging-amqp
+
-
-
-
-
-
-
-
-
+
+ io.quarkus
+ quarkus-rest-client
+
+
+ io.quarkus
+ quarkus-smallrye-fault-tolerance
+
@@ -79,6 +82,7 @@
rest-assured
test
+
diff --git a/bookmark-service/src/main/java/fr/loicmathieu/bookmarkit/AppHealthCheck.java b/bookmark-service/src/main/java/fr/loicmathieu/bookmarkit/AppHealthCheck.java
new file mode 100644
index 0000000..11cb5bf
--- /dev/null
+++ b/bookmark-service/src/main/java/fr/loicmathieu/bookmarkit/AppHealthCheck.java
@@ -0,0 +1,14 @@
+package fr.loicmathieu.bookmarkit;
+
+import org.eclipse.microprofile.health.HealthCheck;
+import org.eclipse.microprofile.health.HealthCheckResponse;
+import org.eclipse.microprofile.health.Readiness;
+
+@Readiness
+public class AppHealthCheck implements HealthCheck {
+
+ @Override
+ public HealthCheckResponse call() {
+ return HealthCheckResponse.builder().name("bookmark").withData("is", "always").up().build();
+ }
+}
diff --git a/bookmark-service/src/main/java/fr/loicmathieu/bookmarkit/BookmarkResource.java b/bookmark-service/src/main/java/fr/loicmathieu/bookmarkit/BookmarkResource.java
index 15f5efd..4b4433f 100644
--- a/bookmark-service/src/main/java/fr/loicmathieu/bookmarkit/BookmarkResource.java
+++ b/bookmark-service/src/main/java/fr/loicmathieu/bookmarkit/BookmarkResource.java
@@ -1,7 +1,19 @@
package fr.loicmathieu.bookmarkit;
-import javax.enterprise.context.ApplicationScoped;
+import io.smallrye.reactive.messaging.annotations.Channel;
+import io.smallrye.reactive.messaging.annotations.Emitter;
+import org.eclipse.microprofile.config.inject.ConfigProperty;
+import org.eclipse.microprofile.faulttolerance.Retry;
+import org.eclipse.microprofile.metrics.annotation.Counted;
+import org.eclipse.microprofile.metrics.annotation.Timed;
+import org.eclipse.microprofile.openapi.annotations.Operation;
+import org.eclipse.microprofile.rest.client.inject.RestClient;
+import org.jboss.logging.Logger;
+
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
import javax.transaction.Transactional;
+import javax.validation.Valid;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
@@ -10,8 +22,10 @@
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriInfo;
import java.net.URI;
import java.util.List;
@@ -20,39 +34,81 @@
@Consumes(MediaType.APPLICATION_JSON)
public class BookmarkResource {
+ private static final Logger LOG = Logger.getLogger(BookmarkResource.class);
+
+ @ConfigProperty(name = "greeting")
+ private String greeting;
+
+ @Channel("bookmarks")
+ private Emitter emitter;
+
+ @RestClient
+ GeoIpService geoIpService;
+
+ @PostConstruct
+ void init() {
+ LOG.infof("Hello %s", greeting);
+ }
+
@GET
- public List listAll(){
+ @Operation(summary = "List all bookmarks")
+ @Counted(name = "listAll.count")
+ @Timed(name = "listAll.time")
+ public List listAll() {
return Bookmark.listAll();
}
@GET
- @Path("/{id}")
+ @Path("{id}")
+ @Operation(summary = "Get a bookmark")
+ @Counted(name = "get.count")
+ @Timed(name = "get.time")
public Bookmark get(@PathParam("id") Long id) {
return Bookmark.findById(id);
}
@POST
@Transactional
- public Response create(Bookmark bookmark){
- bookmark.persist();
- return Response.created(URI.create("/bookmarks/" + bookmark.id)).build();
+ @Operation(summary = "Create a bookmark")
+ @Counted(name = "create.count")
+ @Timed(name = "create.time")
+ @Retry(maxRetries = 2)
+ public Response create(@Valid Bookmark bookmark) {
+ GeoIp geoIp = geoIpService.getIpInfos();
+ if (geoIp != null) {
+ bookmark.location = geoIp.city;
+ bookmark.persist();
+ this.emitter.send(bookmark);
+ return Response.status(Response.Status.CREATED).entity(bookmark).build();
+ } else {
+ return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
+ }
}
@PUT
- @Path("/{id}")
+ @Path("{id}")
@Transactional
- public void update(Bookmark bookmark){
- Bookmark existing = Bookmark.findById(bookmark.id);
- existing.url = bookmark.url;
- existing.description = bookmark.description;
- existing.title = bookmark.title;
+ @Operation(summary = "Update a bookmark")
+ @Counted(name = "update.count")
+ @Timed(name = "update.time")
+ public Response update(@Valid Bookmark bookmark, @PathParam("id") Long id, @Context UriInfo uriInfo) {
+ Bookmark entity = Bookmark.findById(id);
+ entity.description = bookmark.description;
+ entity.location = bookmark.location;
+ entity.title = bookmark.title;
+ entity.url = bookmark.url;
+ return Response.created(URI.create(uriInfo.getPath())).build();
}
@DELETE
- @Path("/{id}")
+ @Path("{id}")
@Transactional
- public void delete(@PathParam("id")Long id){
- Bookmark existing = Bookmark.findById(id);
- existing.delete();
+ @Operation(summary = "Delete a bookmark")
+ @Counted(name = "delete.count")
+ @Timed(name = "delete.time")
+ public Response delete(@PathParam("id") Long id) {
+ Bookmark bookmark = Bookmark.findById(id);
+ bookmark.delete();
+ return Response.noContent().build();
}
}
diff --git a/bookmark-service/src/main/java/fr/loicmathieu/bookmarkit/GeoIp.java b/bookmark-service/src/main/java/fr/loicmathieu/bookmarkit/GeoIp.java
new file mode 100644
index 0000000..8ed2ddc
--- /dev/null
+++ b/bookmark-service/src/main/java/fr/loicmathieu/bookmarkit/GeoIp.java
@@ -0,0 +1,18 @@
+package fr.loicmathieu.bookmarkit;
+
+public class GeoIp {
+ public String query;
+ public String status;
+ public String country;
+ public String countryCode;
+ public String region;
+ public String regionName;
+ public String city;
+ public String zip;
+ public Double lat;
+ public Double lon;
+ public String timezone;
+ public String isp;
+ public String org;
+ public String as;
+}
diff --git a/bookmark-service/src/main/java/fr/loicmathieu/bookmarkit/GeoIpService.java b/bookmark-service/src/main/java/fr/loicmathieu/bookmarkit/GeoIpService.java
new file mode 100644
index 0000000..46f9e47
--- /dev/null
+++ b/bookmark-service/src/main/java/fr/loicmathieu/bookmarkit/GeoIpService.java
@@ -0,0 +1,18 @@
+package fr.loicmathieu.bookmarkit;
+
+import org.eclipse.microprofile.rest.client.inject.RegisterRestClient;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+
+@Path("/geoip")
+@RegisterRestClient
+public interface GeoIpService {
+
+ @GET
+ @Produces(MediaType.APPLICATION_JSON)
+ GeoIp getIpInfos();
+
+}
diff --git a/bookmark-service/src/main/resources/application.properties b/bookmark-service/src/main/resources/application.properties
index 4747645..2184240 100644
--- a/bookmark-service/src/main/resources/application.properties
+++ b/bookmark-service/src/main/resources/application.properties
@@ -1,8 +1,18 @@
+greeting=world
+%dev.greeting=Dev
+fr.loicmathieu.bookmarkit.GeoIpService/mp-rest/url=http://localhost:8093
+# Configures the AMQP broker credentials.
+amqp-username=quarkus
+amqp-password=quarkus
+# Configure the AMQP connector to write to the `bookmark` address
+mp.messaging.outgoing.bookmarks.connector=smallrye-amqp
+mp.messaging.outgoing.bookmarks.address=bookmarks
+mp.messaging.outgoing.bookmarks.durable=true
# Datasource configuration
quarkus.datasource.url=jdbc:postgresql://localhost:5432/bookmarkit
quarkus.datasource.driver=org.postgresql.Driver
-quarkus.datasource.username=quarkus
-quarkus.datasource.password=quarkus
-# drop and create the database at startup (use `update` to only update the schema)
+quarkus.datasource.username=sarah
+quarkus.datasource.password=connor
+# drop and create the database at the startup (use `update` to only update the schema)
quarkus.hibernate-orm.database.generation=drop-and-create
quarkus.hibernate-orm.sql-load-script=import.sql
diff --git a/bookmark-service/src/test/java/fr/loicmathieu/bookmarkit/BookmarkObservabilityTest.java b/bookmark-service/src/test/java/fr/loicmathieu/bookmarkit/BookmarkObservabilityTest.java
index 06ba45f..b152ae1 100644
--- a/bookmark-service/src/test/java/fr/loicmathieu/bookmarkit/BookmarkObservabilityTest.java
+++ b/bookmark-service/src/test/java/fr/loicmathieu/bookmarkit/BookmarkObservabilityTest.java
@@ -20,7 +20,7 @@ void metricsTest() {
.get("/metrics/application")
.then()
.statusCode(200)
- .body("size()", CoreMatchers.is(10));
+ .body("size()", CoreMatchers.is(13));
}
@Test
diff --git a/bookmark-service/src/test/java/fr/loicmathieu/bookmarkit/NativeBookmarkObservabilityIT.java b/bookmark-service/src/test/java/fr/loicmathieu/bookmarkit/NativeBookmarkObservabilityIT.java
new file mode 100644
index 0000000..ea31999
--- /dev/null
+++ b/bookmark-service/src/test/java/fr/loicmathieu/bookmarkit/NativeBookmarkObservabilityIT.java
@@ -0,0 +1,9 @@
+package fr.loicmathieu.bookmarkit;
+
+import io.quarkus.test.junit.NativeImageTest;
+
+@NativeImageTest
+class NativeBookmarkObservabilityIT extends BookmarkObservabilityTest {
+
+ // Execute the same tests but in native mode.
+}
diff --git a/bookmark-service/src/test/java/fr/loicmathieu/bookmarkit/NativeBookmarkResourceIT.java b/bookmark-service/src/test/java/fr/loicmathieu/bookmarkit/NativeBookmarkResourceIT.java
new file mode 100644
index 0000000..24f7ff0
--- /dev/null
+++ b/bookmark-service/src/test/java/fr/loicmathieu/bookmarkit/NativeBookmarkResourceIT.java
@@ -0,0 +1,10 @@
+package fr.loicmathieu.bookmarkit;
+
+import io.quarkus.test.junit.NativeImageTest;
+
+@NativeImageTest
+class NativeBookmarkResourceIT extends BookmarkResourceTest {
+
+ // Execute the same tests but in native mode.
+}
+
diff --git a/docker-compose.yml b/docker-compose.yml
index b34c368..2d865d7 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -12,8 +12,8 @@ services:
ports:
- "5432:5432"
environment:
- - POSTGRES_USER=quarkus
- - POSTGRES_PASSWORD=quarkus
+ - POSTGRES_USER=sarah
+ - POSTGRES_PASSWORD=connor
- POSTGRES_DB=bookmarkit
artemis:
diff --git a/geoip-service/pom.xml b/geoip-service/pom.xml
index eb6f13f..71697fb 100644
--- a/geoip-service/pom.xml
+++ b/geoip-service/pom.xml
@@ -9,7 +9,7 @@
UTF-8
2.22.0
- 0.26.1
+ 1.0.1.Final
UTF-8
1.8
1.8
diff --git a/geoip-service/src/main/java/com/lahzouz/bookmarkit/GeoIp.java b/geoip-service/src/main/java/com/lahzouz/bookmarkit/GeoIp.java
index 4a27385..712e24d 100644
--- a/geoip-service/src/main/java/com/lahzouz/bookmarkit/GeoIp.java
+++ b/geoip-service/src/main/java/com/lahzouz/bookmarkit/GeoIp.java
@@ -1,7 +1,6 @@
package com.lahzouz.bookmarkit;
public class GeoIp {
-
public String query;
public String status;
public String country;
@@ -16,5 +15,4 @@ public class GeoIp {
public String isp;
public String org;
public String as;
-
}
diff --git a/geoip-service/src/main/java/com/lahzouz/bookmarkit/GeoIpResource.java b/geoip-service/src/main/java/com/lahzouz/bookmarkit/GeoIpResource.java
index 22d1449..7aadd58 100644
--- a/geoip-service/src/main/java/com/lahzouz/bookmarkit/GeoIpResource.java
+++ b/geoip-service/src/main/java/com/lahzouz/bookmarkit/GeoIpResource.java
@@ -18,14 +18,13 @@
public class GeoIpResource {
@RestClient
- private GeoIpService geoIpService;
+ GeoIpService geoIpService;
private AtomicBoolean fail = new AtomicBoolean(true);
private AtomicBoolean failIp = new AtomicBoolean(true);
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response findGeoIpInfo() {
-
if (fail.compareAndSet(true, false)) {
return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR).build();
} else {
@@ -38,7 +37,6 @@ public Response findGeoIpInfo() {
@Path("/{ip}")
@Produces(MediaType.APPLICATION_JSON)
public Response findGeoIpInfo(@PathParam("ip") String ip) {
-
if (failIp.compareAndSet(true, false)) {
return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR).build();
} else {
diff --git a/geoip-service/src/main/resources/application.properties b/geoip-service/src/main/resources/application.properties
index 7d3f9eb..9016019 100644
--- a/geoip-service/src/main/resources/application.properties
+++ b/geoip-service/src/main/resources/application.properties
@@ -2,4 +2,3 @@ quarkus.http.port=8093
quarkus.http.test-port=8091
com.lahzouz.bookmarkit.GeoIpService/mp-rest/url=http://ip-api.com
-com.lahzouz.bookmarkit.GeoIpService/mp-rest/scope=javax.inject.Singleton
diff --git a/geoip-service/src/test/java/com/lahzouz/bookmarkit/NativeGeoIpResourceIT.java b/geoip-service/src/test/java/com/lahzouz/bookmarkit/NativeGeoIpResourceIT.java
index 3844a88..b4ea550 100644
--- a/geoip-service/src/test/java/com/lahzouz/bookmarkit/NativeGeoIpResourceIT.java
+++ b/geoip-service/src/test/java/com/lahzouz/bookmarkit/NativeGeoIpResourceIT.java
@@ -1,8 +1,8 @@
package com.lahzouz.bookmarkit;
-import io.quarkus.test.junit.SubstrateTest;
+import io.quarkus.test.junit.NativeImageTest;
-@SubstrateTest
+@NativeImageTest
public class NativeGeoIpResourceIT extends GeoIpResourceTest {
// Execute the same tests but in native mode.