Exercise 4 - Vert.x Event Bus
Last updated
Last updated
The Vert.x Event Bus allows different parts of your application to communicate with each other. Check out the guide to find out more details.
In this lab you'll learn how to use the bus to communicate in-memory between different layers of the 'Articles' service.
The 'Articles' service uses a clean architecture approach. There are three different layers:
API
Business
Data
The API layer contains the implementation of the REST APIs and the external messaging interfaces. The data layer contains the implementation of the persistence and could include calls to other external services. The API layer and the data layer can be easily replaced without changing the business logic.
In this lab you'll use the event bus to communicate between the business and the API layers.
Let's take a look at the implementation of ArticleService in the business layer.
An instance of the bus can be injected via @Inject.
Next let's modify the method 'sendMessageToKafka' slightly by adding a System.out.println.
Exit the Editor via 'Ctrl-X', 'y' and 'Enter'.
The method 'sendMessageToKafka' in the class NewArticleCreatedListener.java in the API layer is invoked when the messages should be sent to Kafka. This is defined via the annotation @ConsumeEvent.
Let's modify this method slightly as well.
Exit the Editor via 'Ctrl-X', 'y' and 'Enter'.
Wait until the build has been completed.
Delete the articles pod. This will trigger Kubernetes to start a new pod with the latest version of the image.
Create a new article by invoking a curl post command. You can get the URL from the script show-urls.
In order to see the logs, you can do two things:
Use the following instructions which leverage a terminal
Use distributed logging as documented in Lab 5
In the terminal get the pod name:
After this invoke this command to display the logs of the pod.
Your added line shows up in the logs now.