Skip to content

Commit d70bcaf

Browse files
committed
feat(*): step 5
feat(*): Add step 5 feat: small enhancements feat: solution for step 5 refactor(*): Update Postman collection
1 parent 3ca019c commit d70bcaf

File tree

9 files changed

+93
-105
lines changed

9 files changed

+93
-105
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ Steps:
6363
- Add a configuration property inside you `application.properties` file: `greeting=World`
6464
- Modify `BookmarkResource` to read this configuration property and log it at startup:
6565
- Use `@ConfigProperty` to inject the property inside a `greeting` variable.
66-
- Create a `@PostConstruct` method that log it via `log.info("Hello {}", greeting)` using [SLFJ](https://www.slf4j.org/).
66+
- 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).
6767
- Test using `mvn quarkus:dev` you should see `Hello World` in the console.
6868
- Add a new line to `application.properties` file: `%dev.greeting=Dev` this is an override of the same property for the dev profile.
6969
- Test using `mvn quarkus:dev` you should see `Hello Dev` in the console.

bookmark-message-consumer/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<surefire-plugin.version>2.22.0</surefire-plugin.version>
1010
<maven.compiler.target>1.8</maven.compiler.target>
1111
<maven.compiler.source>1.8</maven.compiler.source>
12-
<quarkus.version>0.22.0</quarkus.version>
12+
<quarkus.version>0.28.1</quarkus.version>
1313
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1414
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
1515
</properties>

bookmark-service/pom.xml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<surefire-plugin.version>2.22.0</surefire-plugin.version>
1010
<maven.compiler.target>1.8</maven.compiler.target>
1111
<maven.compiler.source>1.8</maven.compiler.source>
12-
<quarkus.version>0.26.1</quarkus.version>
12+
<quarkus.version>0.28.1</quarkus.version>
1313
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1414
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
1515
</properties>
@@ -42,10 +42,13 @@
4242
<groupId>io.quarkus</groupId>
4343
<artifactId>quarkus-smallrye-health</artifactId>
4444
</dependency>
45+
<!-- Step 5 dependencies -->
4546
<dependency>
4647
<groupId>io.quarkus</groupId>
4748
<artifactId>quarkus-jdbc-postgresql</artifactId>
4849
</dependency>
50+
<!--/ Step 5 dependencies -->
51+
<!-- Step 6 dependencies -->
4952
<dependency>
5053
<groupId>io.quarkus</groupId>
5154
<artifactId>quarkus-smallrye-metrics</artifactId>
@@ -74,6 +77,15 @@
7477
<artifactId>quarkus-junit5</artifactId>
7578
<scope>test</scope>
7679
</dependency>
80+
<!--/ Step 6 dependencies -->
81+
82+
83+
<!-- test dependencies-->
84+
<dependency>
85+
<groupId>io.rest-assured</groupId>
86+
<artifactId>rest-assured</artifactId>
87+
<scope>test</scope>
88+
</dependency>
7789
<dependency>
7890
<groupId>io.rest-assured</groupId>
7991
<artifactId>rest-assured</artifactId>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package fr.loicmathieu.bookmarkit;
2+
3+
import org.eclipse.microprofile.health.HealthCheck;
4+
import org.eclipse.microprofile.health.HealthCheckResponse;
5+
import org.eclipse.microprofile.health.Readiness;
6+
7+
@Readiness
8+
public class AppHealthCheck implements HealthCheck {
9+
10+
@Override
11+
public HealthCheckResponse call() {
12+
return HealthCheckResponse.builder().name("bookmark").withData("is", "always").up().build();
13+
}
14+
}
Lines changed: 53 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
package fr.loicmathieu.bookmarkit;
22

3+
import io.smallrye.reactive.messaging.annotations.Channel;
34
import io.smallrye.reactive.messaging.annotations.Emitter;
4-
import io.smallrye.reactive.messaging.annotations.Stream;
55
import org.eclipse.microprofile.config.inject.ConfigProperty;
66
import org.eclipse.microprofile.metrics.annotation.Counted;
77
import org.eclipse.microprofile.metrics.annotation.Timed;
88
import org.eclipse.microprofile.openapi.annotations.Operation;
9-
import org.eclipse.microprofile.reactive.messaging.Outgoing;
9+
import org.jboss.logging.Logger;
1010

1111
import javax.annotation.PostConstruct;
12-
import javax.inject.Inject;
12+
import javax.annotation.PreDestroy;
1313
import javax.transaction.Transactional;
14+
import javax.validation.Valid;
1415
import javax.ws.rs.Consumes;
1516
import javax.ws.rs.DELETE;
1617
import javax.ws.rs.GET;
@@ -19,73 +20,92 @@
1920
import javax.ws.rs.Path;
2021
import javax.ws.rs.PathParam;
2122
import javax.ws.rs.Produces;
23+
import javax.ws.rs.core.Context;
2224
import javax.ws.rs.core.MediaType;
2325
import javax.ws.rs.core.Response;
26+
import javax.ws.rs.core.UriInfo;
2427
import java.net.URI;
2528
import java.util.List;
2629

2730
@Path("/bookmarks")
2831
@Produces(MediaType.APPLICATION_JSON)
2932
@Consumes(MediaType.APPLICATION_JSON)
3033
public class BookmarkResource {
31-
@ConfigProperty(name="greeting") String greeting;
3234

33-
@Inject @Stream("bookmarks") Emitter<Bookmark> emitter;
35+
private static final Logger LOGGER = Logger.getLogger(BookmarkResource.class);
36+
37+
@ConfigProperty(name = "greeting")
38+
private String greeting;
39+
40+
@Channel("bookmarks")
41+
private Emitter<Bookmark> emitter;
3442

3543
@PostConstruct
36-
void init(){
37-
System.out.println("Hello " + greeting);
44+
void init() {
45+
LOGGER.infof("Hello %s", greeting);
46+
}
47+
48+
@PreDestroy
49+
void shutdown() {
50+
if (!emitter.isCancelled()) {
51+
emitter.complete();
52+
}
3853
}
3954

4055
@GET
4156
@Operation(summary = "List all bookmarks")
42-
@Counted(name = "listAll.count")
43-
@Timed(name="listAll.time")
44-
public List<Bookmark> listAll(){
57+
@Counted(name = "listBookmarks.count")
58+
@Timed(name = "listBookmarks.time")
59+
public List<Bookmark> listBookmarks() {
4560
return Bookmark.listAll();
4661
}
4762

4863
@GET
49-
@Path("/{id}")
64+
@Path("{id}")
5065
@Operation(summary = "Get a bookmark")
51-
@Counted(name = "get.count")
52-
@Timed(name="get.time")
53-
public Bookmark get(@PathParam("id") Long id) {
66+
@Counted(name = "getBookmark.count")
67+
@Timed(name = "getBookmark.time")
68+
public Bookmark getBookmark(@PathParam("id") Long id) {
5469
return Bookmark.findById(id);
5570
}
5671

5772
@POST
5873
@Transactional
5974
@Operation(summary = "Create a bookmark")
60-
@Counted(name = "create.count")
61-
@Timed(name="create.time")
62-
public Response create(Bookmark bookmark){
75+
@Counted(name = "createBookmark.count")
76+
@Timed(name = "createBookmark.time")
77+
public Response createBookmark(@Valid Bookmark bookmark) {
6378
bookmark.persist();
64-
emitter.send(bookmark);
65-
return Response.created(URI.create("/bookmarks/" + bookmark.id)).build();
79+
this.emitter.send(bookmark);
80+
return Response.status(Response.Status.CREATED).entity(bookmark).build();
6681
}
6782

6883
@PUT
69-
@Path("/{id}")
84+
@Path("{id}")
7085
@Transactional
7186
@Operation(summary = "Update a bookmark")
72-
@Counted(name = "update.count")
73-
@Timed(name="update.time")
74-
public void update(Bookmark bookmark){
75-
Bookmark existing = Bookmark.findById(bookmark.id);
76-
existing.url = bookmark.url;
77-
existing.description = bookmark.description;
78-
existing.title = bookmark.title;
87+
@Counted(name = "updateBookmark.count")
88+
@Timed(name = "updateBookmark.time")
89+
public Response updateBookmark(@Valid Bookmark bookmark, @PathParam("id") Long id, @Context UriInfo uriInfo) {
90+
Bookmark entity = Bookmark.findById(id);
91+
entity.description = bookmark.description;
92+
entity.location = bookmark.location;
93+
entity.title = bookmark.title;
94+
entity.url = bookmark.url;
95+
return Response.created(URI.create(uriInfo.getPath())).build();
7996
}
8097

8198
@DELETE
82-
@Path("/{id}")
99+
@Path("{id}")
83100
@Transactional
84101
@Operation(summary = "Delete a bookmark")
85-
@Counted(name = "delete.count")
86-
@Timed(name="delete.time")
87-
public void delete(@PathParam("id")Long id){
88-
Bookmark existing = Bookmark.findById(id);
89-
existing.delete();
102+
@Counted(name = "deleteBookmark.count")
103+
@Timed(name = "deleteBookmark.time")
104+
public Response deleteBookmark(@PathParam("id") Long id) {
105+
Bookmark bookmark = Bookmark.findById(id);
106+
if (bookmark.isPersistent()) {
107+
bookmark.delete();
108+
}
109+
return Response.noContent().build();
90110
}
91111
}

bookmark-service/src/main/java/fr/loicmathieu/bookmarkit/MyHealCheck.java

Lines changed: 0 additions & 19 deletions
This file was deleted.
Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
1-
# Datasource configuration
2-
quarkus.datasource.url=jdbc:postgresql://localhost:5432/bookmarkit
3-
quarkus.datasource.driver=org.postgresql.Driver
4-
quarkus.datasource.username=quarkus
5-
quarkus.datasource.password=quarkus
6-
# drop and create the database at startup (use `update` to only update the schema)
7-
quarkus.hibernate-orm.database.generation=drop-and-create
8-
9-
greeting=World
1+
greeting=world
102
%dev.greeting=Dev
11-
123
# Configures the AMQP broker credentials.
134
amqp-username=quarkus
145
amqp-password=quarkus
156
# Configure the AMQP connector to write to the `bookmark` address
167
mp.messaging.outgoing.bookmarks.connector=smallrye-amqp
178
mp.messaging.outgoing.bookmarks.address=bookmarks
18-
mp.messaging.outgoing.bookmarks.durable=true
9+
mp.messaging.outgoing.bookmarks.durable=true
10+
# Datasource configuration
11+
quarkus.datasource.url=jdbc:postgresql://localhost:5432/bookmarkit
12+
quarkus.datasource.driver=org.postgresql.Driver
13+
quarkus.datasource.username=quarkus
14+
quarkus.datasource.password=quarkus
15+
# drop and create the database at startup (use `update` to only update the schema)
16+
quarkus.hibernate-orm.database.generation=drop-and-create
17+
quarkus.hibernate-orm.sql-load-script=import.sql

bookmark-service/src/test/java/fr/loicmathieu/bookmarkit/BookmarkStep2Test.java

Lines changed: 0 additions & 38 deletions
This file was deleted.

geoip-service/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<properties>
1010
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
1111
<surefire-plugin.version>2.22.0</surefire-plugin.version>
12-
<quarkus.version>0.26.1</quarkus.version>
12+
<quarkus.version>0.28.1</quarkus.version>
1313
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1414
<maven.compiler.source>1.8</maven.compiler.source>
1515
<maven.compiler.target>1.8</maven.compiler.target>

0 commit comments

Comments
 (0)