SlideShare a Scribd company logo
Firmansyah.profess@gmail.com
2018
Eclipse Vert.x
Chapter 04
Message Based Microservices
00. HTTP Main Issues
a. Reactive Microservices must be:
• Autonomous
• Asynchronous
• Resilient
• Elastic
b. HTTP based microservices as demonstrated on chapter 03 is not
Reactive Microservices, because it does not provide the resilience and
elasticity.
c. It does not provide the resilience, because if the first microservice
(HttpMicro01 class) fails, we won’t be able to recover by calling
another one.
d. It does not provide the elasticity, if we are under load, creating a new
instance of the HttpMicro01 won’t help us, because HttpMicro02 is
configured to target the HttpMicro01 microservice explicitly.
e. HTTP based microservices can be Reactive Microservices if we
provide some infrastructure to route virtual URLs to a set of service
and a load-balancing strategy to provide elasticity and
health-check support to improve resilience.
00. Message Based MSA
a. The Vert.x Event Bus is messaging backbone for creating Message
Based Microservices Architecture (MSA) that allowing the different
components of an application to interact using messages.
b. Messages are sent to addresses and have a set of headers and a body.
An address is an opaque string representing a destination. Message
consumers register themselves to addresses to receive the messages.
c. The Vert.x Event Bus is also clustered, meaning it can dispatch
messages over the network between distributed senders and
consumers. nodes are connected to enable shared data structure, hard-
stop failure detection, and load-balancing group communication.
d. The Vert.x Event Bus provides three types of delivery semantics:
1. The send method: allows a component to send a message to an
address. If more than one consumer is registered on this address,
Vert.x applies a round-robin strategy to select a consumer.
2. The publish method to deliver the message to all consumers
registered on the address.
3. The send method with a reply handler. This request/
response mechanism allows implementing message-based
asynchronous.
00. Sequence Diagram
We will create two verticle classes with following
sequence diagram to demonstrate Message
based Microservices
MsgMicro02 MsgMicro01
HTTP Request
Address: “AdrMsg”, Message:”Firmansyah”
Reply: “hello Firmansyah”
Reply: “hello Indonesia”
HTTP Response
Address: “AdrMsg”, Message:”Indonesia”
01. Create MsgMicro01 Class
a. Create a directory called “chapter04”
b. Generate the project structure using maven
inside chapter04 folder:
mvn io.fabric8:vertx-maven-plugin:1.0.5:setup 
-DprojectGroupId=io.vertx.chapter04 
-DprojectArtifactId=msg-micro01-vertx-app 
-Dverticle=io.vertx.chapter04.MsgMicro01 
-Ddependencies=infinispan
This command generates:
1. The Maven project structure,
2. Configures the vertx-maven-plugin, and
3. Creates a verticle class (io.vertx.chapter04.MsgMicro01),
4. Adds the Infinispan dependency, an in-memory data grid that will
be used to manage the cluster. Once generated, we may
need to configure Infinispan to build the cluster. The
default configuration uses multicast to discover the nodes.
01. Create MsgMicro01 Class
c. Modify io.vertx.chapter04.MsgMicro01 Class
1. Update start() method :
@Override
public void start() {
// Receive message from the address 'AdrMsg'
vertx.eventBus().<String>consumer("AdrMsg", message -> {
JsonObject json = new JsonObject()
.put("served-by", this.toString());
// Check whether we have received a payload in the
// incoming message
if (message.body().isEmpty()) {
message.reply(json.put("message", "hello"));
} else {
message.reply(json.put("message",
"hello " + message.body()));
}
});
}
01. Create MsgMicro01 Class
Notes:
• This code retrieves the eventBus from the vertx object and
registers a consumer on the address 'AdrMsg'. When a
message is received, it replies to it. Depending on whether or not
the incoming message has an empty body, we compute a
different response. As in the example in the previous chapter, we
send a JSON object back.
• We added the served-by entry in the JSON for knowing from
which instance of MsgMicro01 class will reply the message if we
clustered MsgMicro01 class.
d. Run the MsgMicro01 Class:
mvn compile vertx:run 
-Dvertx.runArgs="-cluster -Djava.net.preferIPv4Stack=true"
The -cluster tells Vert.x to start in cluster mode.
02. Create MsgMicro02 Class
a. Create a directory called “consumer” inside
chapter04 folder
b. Generate the new project structure using
maven inside consumer folder:
mvn io.fabric8:vertx-maven-plugin:1.0.5:setup 
-DprojectGroupId=io.vertx.chapter04 
-DprojectArtifactId=msg-micro02-vertx-app 
-Dverticle= io.vertx.chapter04.MsgMicro02 
-Ddependencies=infinispan,rx
02. Create MsgMicro02 Class
c. Modify io.vertx.chapter04.MsgMicro02 inside
the start method with following logic:
1. Use the event bus to send a message to the 'AdrMsg‘
address and extract the body of the reply.
2. Use the zip operation to retrieve the two responses and build
the final result.
3. In the subscribe method, we print the final result to the console
or print the stack trace.
4. Add an HTTP server, when an HTTP request is received, we
send a message to the 'AdrMsg‘ twice and return the built
result as a HTTP response.
d. Run the MsgMicro02 Class:
mvn compile vertx:run 
-Dvertx.runArgs="-cluster -Djava.net.preferIPv4Stack=true"
e. Browse URL http://localhost:8082/ and
look at the application output.
03. Elasticity Demo
a. Use Ctrl + C to shut down all the application.
b. Package MsgMicro01 app as a fat jar file
mvn clean package
c. Open two different terminals in the chapter04
directory and issue the following command (in
each terminal):
java -jar target/msg-micro01-vertx-app-1.0-SNAPSHOT.jar --
cluster -Djava.net.preferIPv4Stack=true
d. Package MsgMicro02 app as a fat jar file
mvn clean package
e. Open a terminal in the consumer directory and
issue the following command
java -jar target/msg-micro02-vertx-app-1.0-SNAPSHOT.jar --
cluster -Djava.net.preferIPv4Stack=true
f. Browse URL http://localhost:8082/ and
look at the application output.
03. Elasticity Demo Notes
a. Elasticity can be achieved more easily using message
microservices compare to HTTP microservices,
especially using Vertx Tool.
b. HTTP microservices is not enforcing elasticity,
because the HTTP microservice was targeting a
specific instance of the microservice using a hard-
coded URL (IP Address and Port).
c. The two instances of MsgMicro01 are used. The Vert.x
cluster connects two instances, and the event bus is
clustered. Thanks to the event bus round-robin, the
Vert.x event bus dispatches messages to the available
instances and thus balances the load among the
different instances listening to the same address.
d. So, by using the event bus, we have the elasticity
characteristic we need.
04. Resilience Demo
a. Use Ctrl + C to shut down all the application.
b. Modify start() method on
io.vertx.chapter04.MsgMicro01 Class
c. Modify start() method on
io.vertx.chapter04.MsgMicro02 Class
d. Launch MsgMicro01 app in the chapter04 directory
using following command:
mvn compile vertx:run -Dvertx.runArgs="-cluster -
Djava.net.preferIPv4Stack=true"
e. Launch MsgMicro02 app in the consumer directory
using following command:
mvn compile vertx:run -Dvertx.runArgs="-cluster -
Djava.net.preferIPv4Stack=true"
04. Resilience Demo Notes
a. Even though the system get failure or / and don't get
the response, we don’t crash, we don’t limit our
scalability, and we can still handle requests.
b. We implement retry to retrieve the value if it gets a
failure in the form of a timeout or an explicit failure.
c. We implement timeout to improve the user
experience, we should always reply in a timely fashion
to the user, even if we don’t receive the responses
from the service.
d. Now we can reload the page and will always get a
result, even if there are failures or timeouts.
Remember that the thread is not blocked while calling
the service, so we can always accept new requests
and respond to them in a timely fashion.
e. However, this timeout retry often causes more harm
than good, as we will see in the next chapter.
Thank You!
Any questions? You can find me at
firmansyah.profess@gmail.com
Credits
PPT: ALLPPT.com
Music: https://www.bensound.com
Chapter 04: Eclipse Vert.x - Message Based Microservices

More Related Content

Similar to Chapter 04: Eclipse Vert.x - Message Based Microservices

Mvc interview questions – deep dive jinal desai
Mvc interview questions – deep dive   jinal desaiMvc interview questions – deep dive   jinal desai
Mvc interview questions – deep dive jinal desai
jinaldesailive
 
Repository Pattern in MVC3 Application with Entity Framework
Repository Pattern in MVC3 Application with Entity FrameworkRepository Pattern in MVC3 Application with Entity Framework
Repository Pattern in MVC3 Application with Entity FrameworkAkhil Mittal
 
AD0-E116-demo.pdf
AD0-E116-demo.pdfAD0-E116-demo.pdf
AD0-E116-demo.pdf
Tushar Shinde
 
Vert.x for Microservices Architecture
Vert.x for Microservices ArchitectureVert.x for Microservices Architecture
Vert.x for Microservices Architecture
Idan Fridman
 
Mastering Kubernetes - Basics and Advanced Concepts using Example Project
Mastering Kubernetes - Basics and Advanced Concepts using Example ProjectMastering Kubernetes - Basics and Advanced Concepts using Example Project
Mastering Kubernetes - Basics and Advanced Concepts using Example Project
wajrcs
 
Remoting and serialization
Remoting and serializationRemoting and serialization
Remoting and serialization
Chathurangi Shyalika
 
Google cloud certified professional cloud developer practice dumps 2020
Google cloud certified professional cloud developer practice dumps 2020Google cloud certified professional cloud developer practice dumps 2020
Google cloud certified professional cloud developer practice dumps 2020
SkillCertProExams
 
Event driven microservices with vxms, hazelcast and kubernetes - muenchen
Event driven microservices with vxms, hazelcast and kubernetes - muenchenEvent driven microservices with vxms, hazelcast and kubernetes - muenchen
Event driven microservices with vxms, hazelcast and kubernetes - muenchen
Andy Moncsek
 
Rehosting apps between k8s clusters and automating deployment using crane c...
Rehosting apps between k8s clusters and automating deployment using crane   c...Rehosting apps between k8s clusters and automating deployment using crane   c...
Rehosting apps between k8s clusters and automating deployment using crane c...
LibbySchulze
 
Android MVVM architecture using Kotlin, Dagger2, LiveData, MediatorLiveData
Android MVVM architecture using Kotlin, Dagger2, LiveData, MediatorLiveDataAndroid MVVM architecture using Kotlin, Dagger2, LiveData, MediatorLiveData
Android MVVM architecture using Kotlin, Dagger2, LiveData, MediatorLiveData
Waheed Nazir
 
remote method invocation
remote method invocationremote method invocation
remote method invocationArun Nair
 
Orchestraing the Blockchain Using Containers
Orchestraing the Blockchain Using ContainersOrchestraing the Blockchain Using Containers
Orchestraing the Blockchain Using Containers
Andrew Kennedy
 
Debugging Microservices - QCON 2017
Debugging Microservices - QCON 2017Debugging Microservices - QCON 2017
Debugging Microservices - QCON 2017
Idit Levine
 
Design patterns in Magento
Design patterns in MagentoDesign patterns in Magento
Design patterns in Magento
Divante
 
Chapter 06: Eclipse Vert.x - Reactive Microservices with OpenShift
Chapter 06: Eclipse Vert.x - Reactive Microservices with OpenShiftChapter 06: Eclipse Vert.x - Reactive Microservices with OpenShift
Chapter 06: Eclipse Vert.x - Reactive Microservices with OpenShift
Firmansyah, SCJP, OCEWCD, OCEWSD, TOGAF, OCMJEA, CEH
 
Learning MVC Part 3 Creating MVC Application with EntityFramework
Learning MVC Part 3 Creating MVC Application with EntityFrameworkLearning MVC Part 3 Creating MVC Application with EntityFramework
Learning MVC Part 3 Creating MVC Application with EntityFrameworkAkhil Mittal
 
AWS Security Specialty (SCS-C02) Exam | Study Tips & Tricks
AWS Security Specialty (SCS-C02) Exam | Study Tips & TricksAWS Security Specialty (SCS-C02) Exam | Study Tips & Tricks
AWS Security Specialty (SCS-C02) Exam | Study Tips & Tricks
AdinaCoyle
 
Divide and Conquer – Microservices with Node.js
Divide and Conquer – Microservices with Node.jsDivide and Conquer – Microservices with Node.js
Divide and Conquer – Microservices with Node.js
Sebastian Springer
 
Rehosting apps between k8s clusters and automating deployment using crane
Rehosting apps between k8s clusters and automating deployment using craneRehosting apps between k8s clusters and automating deployment using crane
Rehosting apps between k8s clusters and automating deployment using crane
Konveyor Community
 
PRIVATE CLOUD SERVER IMPLEMENTATIONS FOR DATA STORAGE
PRIVATE CLOUD SERVER IMPLEMENTATIONS FOR DATA STORAGEPRIVATE CLOUD SERVER IMPLEMENTATIONS FOR DATA STORAGE
PRIVATE CLOUD SERVER IMPLEMENTATIONS FOR DATA STORAGE
Editor IJCTER
 

Similar to Chapter 04: Eclipse Vert.x - Message Based Microservices (20)

Mvc interview questions – deep dive jinal desai
Mvc interview questions – deep dive   jinal desaiMvc interview questions – deep dive   jinal desai
Mvc interview questions – deep dive jinal desai
 
Repository Pattern in MVC3 Application with Entity Framework
Repository Pattern in MVC3 Application with Entity FrameworkRepository Pattern in MVC3 Application with Entity Framework
Repository Pattern in MVC3 Application with Entity Framework
 
AD0-E116-demo.pdf
AD0-E116-demo.pdfAD0-E116-demo.pdf
AD0-E116-demo.pdf
 
Vert.x for Microservices Architecture
Vert.x for Microservices ArchitectureVert.x for Microservices Architecture
Vert.x for Microservices Architecture
 
Mastering Kubernetes - Basics and Advanced Concepts using Example Project
Mastering Kubernetes - Basics and Advanced Concepts using Example ProjectMastering Kubernetes - Basics and Advanced Concepts using Example Project
Mastering Kubernetes - Basics and Advanced Concepts using Example Project
 
Remoting and serialization
Remoting and serializationRemoting and serialization
Remoting and serialization
 
Google cloud certified professional cloud developer practice dumps 2020
Google cloud certified professional cloud developer practice dumps 2020Google cloud certified professional cloud developer practice dumps 2020
Google cloud certified professional cloud developer practice dumps 2020
 
Event driven microservices with vxms, hazelcast and kubernetes - muenchen
Event driven microservices with vxms, hazelcast and kubernetes - muenchenEvent driven microservices with vxms, hazelcast and kubernetes - muenchen
Event driven microservices with vxms, hazelcast and kubernetes - muenchen
 
Rehosting apps between k8s clusters and automating deployment using crane c...
Rehosting apps between k8s clusters and automating deployment using crane   c...Rehosting apps between k8s clusters and automating deployment using crane   c...
Rehosting apps between k8s clusters and automating deployment using crane c...
 
Android MVVM architecture using Kotlin, Dagger2, LiveData, MediatorLiveData
Android MVVM architecture using Kotlin, Dagger2, LiveData, MediatorLiveDataAndroid MVVM architecture using Kotlin, Dagger2, LiveData, MediatorLiveData
Android MVVM architecture using Kotlin, Dagger2, LiveData, MediatorLiveData
 
remote method invocation
remote method invocationremote method invocation
remote method invocation
 
Orchestraing the Blockchain Using Containers
Orchestraing the Blockchain Using ContainersOrchestraing the Blockchain Using Containers
Orchestraing the Blockchain Using Containers
 
Debugging Microservices - QCON 2017
Debugging Microservices - QCON 2017Debugging Microservices - QCON 2017
Debugging Microservices - QCON 2017
 
Design patterns in Magento
Design patterns in MagentoDesign patterns in Magento
Design patterns in Magento
 
Chapter 06: Eclipse Vert.x - Reactive Microservices with OpenShift
Chapter 06: Eclipse Vert.x - Reactive Microservices with OpenShiftChapter 06: Eclipse Vert.x - Reactive Microservices with OpenShift
Chapter 06: Eclipse Vert.x - Reactive Microservices with OpenShift
 
Learning MVC Part 3 Creating MVC Application with EntityFramework
Learning MVC Part 3 Creating MVC Application with EntityFrameworkLearning MVC Part 3 Creating MVC Application with EntityFramework
Learning MVC Part 3 Creating MVC Application with EntityFramework
 
AWS Security Specialty (SCS-C02) Exam | Study Tips & Tricks
AWS Security Specialty (SCS-C02) Exam | Study Tips & TricksAWS Security Specialty (SCS-C02) Exam | Study Tips & Tricks
AWS Security Specialty (SCS-C02) Exam | Study Tips & Tricks
 
Divide and Conquer – Microservices with Node.js
Divide and Conquer – Microservices with Node.jsDivide and Conquer – Microservices with Node.js
Divide and Conquer – Microservices with Node.js
 
Rehosting apps between k8s clusters and automating deployment using crane
Rehosting apps between k8s clusters and automating deployment using craneRehosting apps between k8s clusters and automating deployment using crane
Rehosting apps between k8s clusters and automating deployment using crane
 
PRIVATE CLOUD SERVER IMPLEMENTATIONS FOR DATA STORAGE
PRIVATE CLOUD SERVER IMPLEMENTATIONS FOR DATA STORAGEPRIVATE CLOUD SERVER IMPLEMENTATIONS FOR DATA STORAGE
PRIVATE CLOUD SERVER IMPLEMENTATIONS FOR DATA STORAGE
 

More from Firmansyah, SCJP, OCEWCD, OCEWSD, TOGAF, OCMJEA, CEH

Microservices Decomposition Patterns.v1.0.20191009
Microservices Decomposition Patterns.v1.0.20191009Microservices Decomposition Patterns.v1.0.20191009
Microservices Decomposition Patterns.v1.0.20191009
Firmansyah, SCJP, OCEWCD, OCEWSD, TOGAF, OCMJEA, CEH
 
Comparison between Oracle JDK, Oracle OpenJDK, and Red Hat OpenJDK.v1.0.20191009
Comparison between Oracle JDK, Oracle OpenJDK, and Red Hat OpenJDK.v1.0.20191009Comparison between Oracle JDK, Oracle OpenJDK, and Red Hat OpenJDK.v1.0.20191009
Comparison between Oracle JDK, Oracle OpenJDK, and Red Hat OpenJDK.v1.0.20191009
Firmansyah, SCJP, OCEWCD, OCEWSD, TOGAF, OCMJEA, CEH
 
Microservices Decomposition Patterns
Microservices Decomposition PatternsMicroservices Decomposition Patterns
Microservices Decomposition Patterns
Firmansyah, SCJP, OCEWCD, OCEWSD, TOGAF, OCMJEA, CEH
 
Comparison between Oracle JDK, Oracle OpenJDK, and Red Hat OpenJDK
Comparison between Oracle JDK, Oracle OpenJDK, and Red Hat OpenJDKComparison between Oracle JDK, Oracle OpenJDK, and Red Hat OpenJDK
Comparison between Oracle JDK, Oracle OpenJDK, and Red Hat OpenJDK
Firmansyah, SCJP, OCEWCD, OCEWSD, TOGAF, OCMJEA, CEH
 
Chapter 02: Eclipse Vert.x - Java First Verticle
Chapter 02: Eclipse Vert.x - Java First VerticleChapter 02: Eclipse Vert.x - Java First Verticle
Chapter 02: Eclipse Vert.x - Java First Verticle
Firmansyah, SCJP, OCEWCD, OCEWSD, TOGAF, OCMJEA, CEH
 
Liferay Platform Overview
Liferay Platform OverviewLiferay Platform Overview
Solution Architecture Framework
Solution Architecture FrameworkSolution Architecture Framework
Solution Architecture Definition
Solution Architecture DefinitionSolution Architecture Definition
Mobile Application Development Platform 2017
Mobile Application Development Platform 2017Mobile Application Development Platform 2017
Mobile Application Development Platform 2017
Firmansyah, SCJP, OCEWCD, OCEWSD, TOGAF, OCMJEA, CEH
 

More from Firmansyah, SCJP, OCEWCD, OCEWSD, TOGAF, OCMJEA, CEH (9)

Microservices Decomposition Patterns.v1.0.20191009
Microservices Decomposition Patterns.v1.0.20191009Microservices Decomposition Patterns.v1.0.20191009
Microservices Decomposition Patterns.v1.0.20191009
 
Comparison between Oracle JDK, Oracle OpenJDK, and Red Hat OpenJDK.v1.0.20191009
Comparison between Oracle JDK, Oracle OpenJDK, and Red Hat OpenJDK.v1.0.20191009Comparison between Oracle JDK, Oracle OpenJDK, and Red Hat OpenJDK.v1.0.20191009
Comparison between Oracle JDK, Oracle OpenJDK, and Red Hat OpenJDK.v1.0.20191009
 
Microservices Decomposition Patterns
Microservices Decomposition PatternsMicroservices Decomposition Patterns
Microservices Decomposition Patterns
 
Comparison between Oracle JDK, Oracle OpenJDK, and Red Hat OpenJDK
Comparison between Oracle JDK, Oracle OpenJDK, and Red Hat OpenJDKComparison between Oracle JDK, Oracle OpenJDK, and Red Hat OpenJDK
Comparison between Oracle JDK, Oracle OpenJDK, and Red Hat OpenJDK
 
Chapter 02: Eclipse Vert.x - Java First Verticle
Chapter 02: Eclipse Vert.x - Java First VerticleChapter 02: Eclipse Vert.x - Java First Verticle
Chapter 02: Eclipse Vert.x - Java First Verticle
 
Liferay Platform Overview
Liferay Platform OverviewLiferay Platform Overview
Liferay Platform Overview
 
Solution Architecture Framework
Solution Architecture FrameworkSolution Architecture Framework
Solution Architecture Framework
 
Solution Architecture Definition
Solution Architecture DefinitionSolution Architecture Definition
Solution Architecture Definition
 
Mobile Application Development Platform 2017
Mobile Application Development Platform 2017Mobile Application Development Platform 2017
Mobile Application Development Platform 2017
 

Recently uploaded

AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
Google
 
Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with Platformless
WSO2
 
RISE with SAP and Journey to the Intelligent Enterprise
RISE with SAP and Journey to the Intelligent EnterpriseRISE with SAP and Journey to the Intelligent Enterprise
RISE with SAP and Journey to the Intelligent Enterprise
Srikant77
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
takuyayamamoto1800
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
Adele Miller
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Globus
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
Max Andersen
 
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Anthony Dahanne
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Globus
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
Ortus Solutions, Corp
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
Paco van Beckhoven
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
NYGGS Automation Suite
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
Globus
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New Zealand
IES VE
 
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Mind IT Systems
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
wottaspaceseo
 
A Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdfA Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdf
kalichargn70th171
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
Cyanic lab
 
Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"
Donna Lenk
 
Graphic Design Crash Course for beginners
Graphic Design Crash Course for beginnersGraphic Design Crash Course for beginners
Graphic Design Crash Course for beginners
e20449
 

Recently uploaded (20)

AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
 
Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with Platformless
 
RISE with SAP and Journey to the Intelligent Enterprise
RISE with SAP and Journey to the Intelligent EnterpriseRISE with SAP and Journey to the Intelligent Enterprise
RISE with SAP and Journey to the Intelligent Enterprise
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
 
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New Zealand
 
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
 
A Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdfA Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdf
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
 
Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"
 
Graphic Design Crash Course for beginners
Graphic Design Crash Course for beginnersGraphic Design Crash Course for beginners
Graphic Design Crash Course for beginners
 

Chapter 04: Eclipse Vert.x - Message Based Microservices

  • 2. 00. HTTP Main Issues a. Reactive Microservices must be: • Autonomous • Asynchronous • Resilient • Elastic b. HTTP based microservices as demonstrated on chapter 03 is not Reactive Microservices, because it does not provide the resilience and elasticity. c. It does not provide the resilience, because if the first microservice (HttpMicro01 class) fails, we won’t be able to recover by calling another one. d. It does not provide the elasticity, if we are under load, creating a new instance of the HttpMicro01 won’t help us, because HttpMicro02 is configured to target the HttpMicro01 microservice explicitly. e. HTTP based microservices can be Reactive Microservices if we provide some infrastructure to route virtual URLs to a set of service and a load-balancing strategy to provide elasticity and health-check support to improve resilience.
  • 3. 00. Message Based MSA a. The Vert.x Event Bus is messaging backbone for creating Message Based Microservices Architecture (MSA) that allowing the different components of an application to interact using messages. b. Messages are sent to addresses and have a set of headers and a body. An address is an opaque string representing a destination. Message consumers register themselves to addresses to receive the messages. c. The Vert.x Event Bus is also clustered, meaning it can dispatch messages over the network between distributed senders and consumers. nodes are connected to enable shared data structure, hard- stop failure detection, and load-balancing group communication. d. The Vert.x Event Bus provides three types of delivery semantics: 1. The send method: allows a component to send a message to an address. If more than one consumer is registered on this address, Vert.x applies a round-robin strategy to select a consumer. 2. The publish method to deliver the message to all consumers registered on the address. 3. The send method with a reply handler. This request/ response mechanism allows implementing message-based asynchronous.
  • 4. 00. Sequence Diagram We will create two verticle classes with following sequence diagram to demonstrate Message based Microservices MsgMicro02 MsgMicro01 HTTP Request Address: “AdrMsg”, Message:”Firmansyah” Reply: “hello Firmansyah” Reply: “hello Indonesia” HTTP Response Address: “AdrMsg”, Message:”Indonesia”
  • 5. 01. Create MsgMicro01 Class a. Create a directory called “chapter04” b. Generate the project structure using maven inside chapter04 folder: mvn io.fabric8:vertx-maven-plugin:1.0.5:setup -DprojectGroupId=io.vertx.chapter04 -DprojectArtifactId=msg-micro01-vertx-app -Dverticle=io.vertx.chapter04.MsgMicro01 -Ddependencies=infinispan This command generates: 1. The Maven project structure, 2. Configures the vertx-maven-plugin, and 3. Creates a verticle class (io.vertx.chapter04.MsgMicro01), 4. Adds the Infinispan dependency, an in-memory data grid that will be used to manage the cluster. Once generated, we may need to configure Infinispan to build the cluster. The default configuration uses multicast to discover the nodes.
  • 6. 01. Create MsgMicro01 Class c. Modify io.vertx.chapter04.MsgMicro01 Class 1. Update start() method : @Override public void start() { // Receive message from the address 'AdrMsg' vertx.eventBus().<String>consumer("AdrMsg", message -> { JsonObject json = new JsonObject() .put("served-by", this.toString()); // Check whether we have received a payload in the // incoming message if (message.body().isEmpty()) { message.reply(json.put("message", "hello")); } else { message.reply(json.put("message", "hello " + message.body())); } }); }
  • 7. 01. Create MsgMicro01 Class Notes: • This code retrieves the eventBus from the vertx object and registers a consumer on the address 'AdrMsg'. When a message is received, it replies to it. Depending on whether or not the incoming message has an empty body, we compute a different response. As in the example in the previous chapter, we send a JSON object back. • We added the served-by entry in the JSON for knowing from which instance of MsgMicro01 class will reply the message if we clustered MsgMicro01 class. d. Run the MsgMicro01 Class: mvn compile vertx:run -Dvertx.runArgs="-cluster -Djava.net.preferIPv4Stack=true" The -cluster tells Vert.x to start in cluster mode.
  • 8. 02. Create MsgMicro02 Class a. Create a directory called “consumer” inside chapter04 folder b. Generate the new project structure using maven inside consumer folder: mvn io.fabric8:vertx-maven-plugin:1.0.5:setup -DprojectGroupId=io.vertx.chapter04 -DprojectArtifactId=msg-micro02-vertx-app -Dverticle= io.vertx.chapter04.MsgMicro02 -Ddependencies=infinispan,rx
  • 9. 02. Create MsgMicro02 Class c. Modify io.vertx.chapter04.MsgMicro02 inside the start method with following logic: 1. Use the event bus to send a message to the 'AdrMsg‘ address and extract the body of the reply. 2. Use the zip operation to retrieve the two responses and build the final result. 3. In the subscribe method, we print the final result to the console or print the stack trace. 4. Add an HTTP server, when an HTTP request is received, we send a message to the 'AdrMsg‘ twice and return the built result as a HTTP response. d. Run the MsgMicro02 Class: mvn compile vertx:run -Dvertx.runArgs="-cluster -Djava.net.preferIPv4Stack=true" e. Browse URL http://localhost:8082/ and look at the application output.
  • 10. 03. Elasticity Demo a. Use Ctrl + C to shut down all the application. b. Package MsgMicro01 app as a fat jar file mvn clean package c. Open two different terminals in the chapter04 directory and issue the following command (in each terminal): java -jar target/msg-micro01-vertx-app-1.0-SNAPSHOT.jar -- cluster -Djava.net.preferIPv4Stack=true d. Package MsgMicro02 app as a fat jar file mvn clean package e. Open a terminal in the consumer directory and issue the following command java -jar target/msg-micro02-vertx-app-1.0-SNAPSHOT.jar -- cluster -Djava.net.preferIPv4Stack=true f. Browse URL http://localhost:8082/ and look at the application output.
  • 11. 03. Elasticity Demo Notes a. Elasticity can be achieved more easily using message microservices compare to HTTP microservices, especially using Vertx Tool. b. HTTP microservices is not enforcing elasticity, because the HTTP microservice was targeting a specific instance of the microservice using a hard- coded URL (IP Address and Port). c. The two instances of MsgMicro01 are used. The Vert.x cluster connects two instances, and the event bus is clustered. Thanks to the event bus round-robin, the Vert.x event bus dispatches messages to the available instances and thus balances the load among the different instances listening to the same address. d. So, by using the event bus, we have the elasticity characteristic we need.
  • 12. 04. Resilience Demo a. Use Ctrl + C to shut down all the application. b. Modify start() method on io.vertx.chapter04.MsgMicro01 Class c. Modify start() method on io.vertx.chapter04.MsgMicro02 Class d. Launch MsgMicro01 app in the chapter04 directory using following command: mvn compile vertx:run -Dvertx.runArgs="-cluster - Djava.net.preferIPv4Stack=true" e. Launch MsgMicro02 app in the consumer directory using following command: mvn compile vertx:run -Dvertx.runArgs="-cluster - Djava.net.preferIPv4Stack=true"
  • 13. 04. Resilience Demo Notes a. Even though the system get failure or / and don't get the response, we don’t crash, we don’t limit our scalability, and we can still handle requests. b. We implement retry to retrieve the value if it gets a failure in the form of a timeout or an explicit failure. c. We implement timeout to improve the user experience, we should always reply in a timely fashion to the user, even if we don’t receive the responses from the service. d. Now we can reload the page and will always get a result, even if there are failures or timeouts. Remember that the thread is not blocked while calling the service, so we can always accept new requests and respond to them in a timely fashion. e. However, this timeout retry often causes more harm than good, as we will see in the next chapter.
  • 14. Thank You! Any questions? You can find me at firmansyah.profess@gmail.com Credits PPT: ALLPPT.com Music: https://www.bensound.com