- Lab
-
Libraries: If you want this lab, consider one of these libraries.
- Core Tech
Guided: Implementing Event-Driven Communication in Quarkus
This Code Lab covers how to build resilient, decoupled microservices using event-driven patterns in Quarkus. You will learn to implement asynchronous messaging using the SmallRye Reactive Messaging framework, produce and consume events, and ensure reliability with built-in fault tolerance strategies.
Lab Info
Table of Contents
-
Challenge
Introduction
Welcome to this Code Lab on building event-driven microservices with Quarkus!
In modern applications, services need to communicate in a way that is both efficient and resilient. Tightly coupling services with direct, synchronous calls can lead to fragile systems that are difficult to scale and maintain.
Event-driven architecture solves this by decoupling services. Instead of calling each other directly, services communicate by producing and consuming events through a message broker. This allows for asynchronous communication, improving scalability and resilience.
In this lab, you will build a two-service application:
- An
order-servicethat exposes a REST endpoint to create orders and publishes anOrderCreatedevent. - An
inventory-servicethat listens forOrderCreatedevents and processes them.
You will use Quarkus and the SmallRye Reactive Messaging framework to implement this pattern. You won't need any external message brokers like Kafka or RabbitMQ; you'll use the convenient in-memory connector provided by SmallRye, which is ideal for a lab environment.
info > This lab experience was developed by the Pluralsight team using Forge, an internally developed AI tool utilizing Gemini technology. All sections were verified by human experts for accuracy prior to publication. For issue reporting, please contact us.
- An
-
Challenge
Step 2: Configure the Order Service (Producer)
First, you'll set up the
order-service, which will act as your event producer. This involves defining the data structure for your event and configuring the messaging channel where events will be sent. -
Challenge
Step 3: Implement Event Production Logic
Now that the producer service is configured, implement the logic to generate and send events. You'll create a service bean to handle event emission and a REST endpoint to trigger it.
-
Challenge
Step 4: Configure the Inventory Service (Consumer)
With the producer complete, it's time to build the consumer. You'll switch to the
inventory-servicemodule and set it up to listen for the events being produced by theorder-service. -
Challenge
Step 5: Implement Event Consumption and Fault Tolerance
In this step, you will implement the core logic of the
inventory-service. You'll create a consumer that processes incoming order events and add a fault tolerance mechanism to make your service more robust. -
Challenge
Step 6: Running and Verifying the Application
Congrats! You have built and configured both microservices! Now it's time to see them work together. You will run both services and send a request to the
order-serviceto confirm that theinventory-servicereceives the event.To run the application and see the result, follow these steps:
- In the first terminal, run the
combined-service:mvn quarkus:dev -pl combined-service - In this second terminal, use
curlto post a new order:curl -X POST -H "Content-Type: application/json" -d '{"orderId":"order-123","itemId":"item-456","quantity":5}' http://localhost:8080/orders - Observe the output in the
combined-serviceterminal. You should see a log line likeProcessing order: order-123, confirming that the event was produced, sent, received, and processed asynchronously!
- In the first terminal, run the
About the author
Real skill practice before real-world application
Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.
Learn by doing
Engage hands-on with the tools and technologies you’re learning. You pick the skill, we provide the credentials and environment.
Follow your guide
All labs have detailed instructions and objectives, guiding you through the learning process and ensuring you understand every step.
Turn time into mastery
On average, you retain 75% more of your learning if you take time to practice. Hands-on labs set you up for success to make those skills stick.