Reactive Messaging with Quarkus on OpenShift
  • Introduction
  • Setup the IBM Cloud Environment
    • Introduction
    • Access the Cluster
    • Access IBM Cloud Shell
  • Setup the sample application
    • Exercise 1 - Setup via Script
    • YouTube - How to setup the sample application (optional)
  • Build new version of the Microservice
    • Exercise 2 - Reactive Messaging with MicroProfile
    • Exercise 3 - Server Sent Events
    • Exercise 4 - Vert.x Event Bus
    • Exercise 5 (optional) - Use distributed Logging
  • Resources
    • How to setup the reactive sample application on OpenShift
    • Blog posts related to reactive
    • Workshop: Reactive Endpoint with Quarkus on OpenShift
    • Cloud-Native-Starter project
    • Cloud-Native-Starter project reactive
Powered by GitBook
On this page
  • Step 1: Understand the Publisher
  • Step 2: Understand the Subscriber
  • Step 3: Deploy new Version
  • Step 4: Deploy new Version

Was this helpful?

  1. Build new version of the Microservice

Exercise 4 - Vert.x Event Bus

PreviousExercise 3 - Server Sent EventsNextExercise 5 (optional) - Use distributed Logging

Last updated 4 years ago

Was this helpful?

The allows different parts of your application to communicate with each other. Check out the 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.

Step 1: Understand the Publisher

cd ~/cloud-native-starter/reactive/articles-reactive/src/main/java/com/ibm/articles/
cat business/ArticleService.java

An instance of the bus can be injected via @Inject.

Next let's modify the method 'sendMessageToKafka' slightly by adding a System.out.println.

System.out.println("Sending message via Vert.x Event Bus");
cd ~/cloud-native-starter/reactive/articles-reactive/src/main/java/com/ibm/articles/
nano business/ArticleService.java

Exit the Editor via 'Ctrl-X', 'y' and 'Enter'.

Step 2: Understand the Subscriber

Let's modify this method slightly as well.

System.out.println("Receiving message via Vert.x Event Bus");
cd ~/cloud-native-starter/reactive/articles-reactive/src/main/java/com/ibm/articles/
nano apis/NewArticleCreatedListener.java

Exit the Editor via 'Ctrl-X', 'y' and 'Enter'.

Step 3: Deploy new Version

cd ~/cloud-native-starter/reactive/articles-reactive
oc start-build articles-reactive --from-dir=.

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.

Step 4: Deploy new Version

Create a new article by invoking a curl post command. You can get the URL from the script show-urls.

~/cloud-native-starter/reactive/os4-scripts/show-urls.sh

In order to see the logs, you can do two things:

  1. Use the following instructions which leverage a terminal

In the terminal get the pod name:

oc get pods

After this invoke this command to display the logs of the pod.

oc logs articles-reactive-xxxxxxxxxxx-xxxxx

Your added line shows up in the logs now.

Let's take a look at the implementation of in the business layer.

The method 'sendMessageToKafka' in the class in the API layer is invoked when the messages should be sent to Kafka. This is defined via the annotation @ConsumeEvent.

Use distributed logging as documented in

ArticleService
NewArticleCreatedListener.java
Lab 5
Vert.x Event Bus
guide