Skip to content

Commit 175a0f3

Browse files
committed
feat: solution for step 5
1 parent c1918a9 commit 175a0f3

File tree

3 files changed

+22
-7
lines changed

3 files changed

+22
-7
lines changed

bookmark-service/pom.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@
5353
<artifactId>quarkus-smallrye-metrics</artifactId>
5454
</dependency>
5555
<!-- Step 5 dependencies -->
56-
<!-- <dependency>-->
57-
<!-- <groupId>io.quarkus</groupId>-->
58-
<!-- <artifactId>quarkus-smallrye-reactive-messaging-amqp</artifactId>-->
59-
<!-- </dependency>-->
56+
<dependency>
57+
<groupId>io.quarkus</groupId>
58+
<artifactId>quarkus-smallrye-reactive-messaging-amqp</artifactId>
59+
</dependency>
6060
<!--/ Step 5 dependencies -->
6161
<!-- Step 6 dependencies -->
6262
<!-- <dependency>-->

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

Lines changed: 9 additions & 2 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,6 +28,9 @@
2528
@Produces(MediaType.APPLICATION_JSON)
2629
@Consumes(MediaType.APPLICATION_JSON)
2730
public class BookmarkResource {
31+
@ConfigProperty(name="greeting") String greeting;
32+
33+
@Inject @Stream("bookmarks") Emitter<Bookmark> emitter;
2834

2935
private static final Logger LOGGER = LoggerFactory.getLogger(BookmarkResource.class);
3036

@@ -61,11 +67,12 @@ public Bookmark getBookmark(@PathParam("id") Long id) {
6167
@Timed(name = "createBookmark.time")
6268
public Response createBookmark(Bookmark bookmark) {
6369
bookmark.persist();
70+
emitter.send(bookmark);
6471
return Response.status(Response.Status.CREATED).entity(bookmark).build();
6572
}
6673

6774
@PUT
68-
@Path("/{id}")
75+
@Path("{id}")
6976
@Transactional
7077
@Operation(summary = "Update a bookmark")
7178
@Counted(name = "updateBookmark.count")
@@ -79,7 +86,7 @@ public void updateBookmark(Bookmark bookmark, @PathParam("id") Long id) {
7986
}
8087

8188
@DELETE
82-
@Path("/{id}")
89+
@Path("{id}")
8390
@Transactional
8491
@Operation(summary = "Delete a bookmark")
8592
@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)