Playing around with events in Spring based on this documentation .
As an example, this module contains an application that allows clients notifying about the existence of a new book that is saved to the bookshelf. Clients can then obtain the ID of all the books in the bookshelf.
The goal is that the act of saving the book to the bookshelf is an event.
It's a Spring boot application exposed through
the BooksController
.
Calling the /new-book-notify
endpoint triggers the publishing of
a NewBookEvent.
The NewBookEventListener
is subscribed to the event and is responsible for saving the new book information to the bookshelf.
From the root folder, execute:
./mvnw clean package
java -jar spring-events/target/app.jar
This will start the Springboot application on port 8080. To interact with the API:
curl http://localhost:8080/books/notify-new-book -X POST --header "Content-Type: application/json" --data '{"title":"A Study in Scarlet"}'
The response body should contain a non-empty list.