Skip to content

Commit 8facc94

Browse files
committed
feat: solution for step 5
1 parent c442a38 commit 8facc94

File tree

3 files changed

+22
-10
lines changed

3 files changed

+22
-10
lines changed

bookmark-service/pom.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,10 @@
5151
<artifactId>quarkus-smallrye-metrics</artifactId>
5252
</dependency>
5353
<!-- Step 5 dependencies -->
54-
<!-- <dependency>-->
55-
<!-- <groupId>io.quarkus</groupId>-->
56-
<!-- <artifactId>quarkus-smallrye-reactive-messaging-amqp</artifactId>-->
57-
<!-- </dependency>-->
54+
<dependency>
55+
<groupId>io.quarkus</groupId>
56+
<artifactId>quarkus-smallrye-reactive-messaging-amqp</artifactId>
57+
</dependency>
5858
<!--/ Step 5 dependencies -->
5959
<!-- Step 6 dependencies -->
6060
<!-- <dependency>-->

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package fr.loicmathieu.bookmarkit;
22

3+
import io.smallrye.reactive.messaging.annotations.Emitter;
4+
import io.smallrye.reactive.messaging.annotations.Stream;
35
import org.eclipse.microprofile.config.inject.ConfigProperty;
46
import org.eclipse.microprofile.metrics.annotation.Counted;
57
import org.eclipse.microprofile.metrics.annotation.Timed;
@@ -8,6 +10,7 @@
810
import org.slf4j.LoggerFactory;
911

1012
import javax.annotation.PostConstruct;
13+
import javax.inject.Inject;
1114
import javax.transaction.Transactional;
1215
import javax.ws.rs.Consumes;
1316
import javax.ws.rs.DELETE;
@@ -25,11 +28,11 @@
2528
@Produces(MediaType.APPLICATION_JSON)
2629
@Consumes(MediaType.APPLICATION_JSON)
2730
public class BookmarkResource {
31+
@ConfigProperty(name="greeting") String greeting;
2832

29-
private static final Logger LOGGER = LoggerFactory.getLogger(BookmarkResource.class);
33+
@Inject @Stream("bookmarks") Emitter<Bookmark> emitter;
3034

31-
@ConfigProperty(name = "greeting")
32-
private String greeting;
35+
private static final Logger LOGGER = LoggerFactory.getLogger(BookmarkResource.class);
3336

3437
@PostConstruct
3538
void init() {
@@ -61,11 +64,12 @@ public Bookmark getBookmark(@PathParam("id") Long id) {
6164
@Timed(name = "createBookmark.time")
6265
public Response createBookmark(Bookmark bookmark) {
6366
bookmark.persist();
67+
emitter.send(bookmark);
6468
return Response.status(Response.Status.CREATED).entity(bookmark).build();
6569
}
6670

6771
@PUT
68-
@Path("/{id}")
72+
@Path("{id}")
6973
@Transactional
7074
@Operation(summary = "Update a bookmark")
7175
@Counted(name = "updateBookmark.count")
@@ -79,7 +83,7 @@ public void updateBookmark(Bookmark bookmark, @PathParam("id") Long id) {
7983
}
8084

8185
@DELETE
82-
@Path("/{id}")
86+
@Path("{id}")
8387
@Transactional
8488
@Operation(summary = "Delete a bookmark")
8589
@Counted(name = "deleteBookmark.count")

bookmark-service/src/main/resources/application.properties

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,12 @@ quarkus.hibernate-orm.database.generation=drop-and-create
88
quarkus.hibernate-orm.sql-load-script=import.sql
99

1010
greeting=World
11-
%dev.greeting=Dev
11+
%dev.greeting=Dev
12+
13+
# Configures the AMQP broker credentials.
14+
amqp-username=quarkus
15+
amqp-password=quarkus
16+
# Configure the AMQP connector to write to the `bookmark` address
17+
mp.messaging.outgoing.bookmarks.connector=smallrye-amqp
18+
mp.messaging.outgoing.bookmarks.address=bookmarks
19+
mp.messaging.outgoing.bookmarks.durable=true

0 commit comments

Comments
 (0)