SlideShare a Scribd company logo
1 of 10
Firmansyah.profess@gmail.com
2018
Eclipse Vert.x
Chapter 03
HTTP Based Microservices
00. Sequence Diagram
We will create two verticle classes with following
sequence diagram to demonstrate HTTP based
Microservices
HttpMicro02 HttpMicro01
HTTP Request
HTTP Request /Firmansyah
HTTP Request /Indonesia
HTTP Response “hello Firmansyah”
HTTP Response “hello Indonesia”
HTTP Response
01. Create HttpMicro01 Class
a. Create a directory called “chapter03”
b. Generate the project structure using
maven inside chapter03 folder:
mvn io.fabric8:vertx-maven-plugin:1.0.5:setup 
-DprojectGroupId=io.vertx.chapter03 
-DprojectArtifactId=http-micro-vertx-app 
-Dverticle=io.vertx.chapter03.HttpMicro01 
-Ddependencies=web
This command generates:
1. The Maven project structure,
2. Configures the vertx-maven-plugin, and
3. Creates a verticle class (io.vertx.chapter03.HttpMicro01),
4. Adds the vertx-web dependency, Vert.x Web is a module
that provides everything you need to build modern web
applications on top of Vert.x.
01. Create HttpMicro01 Class
c. Modify io.vertx.chapter03.HttpMicro01 Class
1. Create method for JSON HTTP response (Vert.x provides a
JsonObject class to create and manipulate JSON
structures.):
private void helloJson(RoutingContext rc) {
String message = "hello";
if (rc.pathParam("name") != null) {
message += " " + rc.pathParam("name");
}
JsonObject json = new JsonObject().put("message", message);
rc.response()
.putHeader(HttpHeaders.CONTENT_TYPE, "application/json")
.end(json.encode());
}
2. Add logic for HTTP Server creation, routes and
parameters request handling inside the start()
method:
01. Create HttpMicro01 Class
public void start() {
Router router = Router.router(vertx);
router.get("/").handler(this::helloJson);
router.get("/:name").handler(this::helloJson);
vertx.createHttpServer()
.requestHandler(router::accept)
.listen(8080);
}
Notes:
• This code creates an HTTP server on port 8080 and registers a
requestHandler and use the accept method of the router.
• Vert.x Web provides a Router on which we can register Routes.
Routes are the mechanism by which Vert.x Web checks the path
and invokes the associated action.
• Once we have created the Router object, we register two
routes. The first one handles requests on / and just writes
hello. The second route has a path parameter (:name).
The handler will call helloJson to return JSON response
01. Create HttpMicro01 Class
d. Package app as a fat jar, launch:
mvn clean package
e. Run this application, launch:
java -jar target/http-micro-vertx-app-1.0-SNAPSHOT.jar
f. Browse URL http://localhost:8080/ and look at
the application output.
g. Use Ctrl + C to shut down.
02. Create HttpMicro02 Class
a. Create a directory called “consumer” inside
chapter03 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.chapter03 
-DprojectArtifactId=http-micro02-vertx-app 
-Dverticle=io.vertx.chapter03.HttpMicro02 
-Ddependencies=web,web-client,rx
Notes:
1. The last command adds another dependency: the Vert.x web
client, an asynchronous HTTP client. We will use this client
to call the first microservice (HttpMicro01 class).
2. The command has also added the Vert.x RxJava binding.
02. Create HttpMicro02 Class
c. Modify io.vertx.chapter03.HttpMicro02
1. In the start method, we create a WebClient and a Router.
2. On the created router, we register a route on “/” and start the
HTTP server, passing the router accept method as
requestHandler.
3. The handler of the route is a method
invokeHttpMicro01() with following logic:
• Uses the web client to invoke the first microservice with a
specific path (/firmansyah)
• The handler we passed in into request.send() is
invoked when either the response arrives or an error
occurs.
• When it succeeds, we write the received payload to the
response; otherwise, we reply with a 500 response
Thank You!
Any questions? You can find me at
firmansyah.profess@gmail.com
Credits
PPT: ALLPPT.com
Music: https://www.bensound.com
Chapter 03: Eclipse Vert.x - HTTP Based Microservices

More Related Content

What's hot

Asp.net page lifecycle
Asp.net page lifecycleAsp.net page lifecycle
Asp.net page lifecycleKhademulBasher
 
( 16 ) Office 2007 Create An Extranet Site With Forms Authentication
( 16 ) Office 2007   Create An Extranet Site With Forms Authentication( 16 ) Office 2007   Create An Extranet Site With Forms Authentication
( 16 ) Office 2007 Create An Extranet Site With Forms AuthenticationLiquidHub
 
Python/Flask Presentation
Python/Flask PresentationPython/Flask Presentation
Python/Flask PresentationParag Mujumdar
 
Servlet LifeCycle Demo App
Servlet LifeCycle Demo  AppServlet LifeCycle Demo  App
Servlet LifeCycle Demo AppPeeyush Ranjan
 
KOIN for dependency Injection
KOIN for dependency InjectionKOIN for dependency Injection
KOIN for dependency InjectionKirill Rozov
 
ASP.NET Page life cycle and ViewState
ASP.NET Page life cycle and ViewStateASP.NET Page life cycle and ViewState
ASP.NET Page life cycle and ViewStateMindfire Solutions
 
Get started with meteor | designveloper software agency meteor prime partner
Get started with meteor | designveloper software agency   meteor prime partnerGet started with meteor | designveloper software agency   meteor prime partner
Get started with meteor | designveloper software agency meteor prime partnerDesignveloper
 
Spring boot Introduction
Spring boot IntroductionSpring boot Introduction
Spring boot IntroductionJeevesh Pandey
 
Migration from vaadin 6 to vaadin 7 devoxx france 2013
Migration from vaadin 6 to vaadin 7   devoxx france 2013Migration from vaadin 6 to vaadin 7   devoxx france 2013
Migration from vaadin 6 to vaadin 7 devoxx france 2013Joonas Lehtinen
 

What's hot (9)

Asp.net page lifecycle
Asp.net page lifecycleAsp.net page lifecycle
Asp.net page lifecycle
 
( 16 ) Office 2007 Create An Extranet Site With Forms Authentication
( 16 ) Office 2007   Create An Extranet Site With Forms Authentication( 16 ) Office 2007   Create An Extranet Site With Forms Authentication
( 16 ) Office 2007 Create An Extranet Site With Forms Authentication
 
Python/Flask Presentation
Python/Flask PresentationPython/Flask Presentation
Python/Flask Presentation
 
Servlet LifeCycle Demo App
Servlet LifeCycle Demo  AppServlet LifeCycle Demo  App
Servlet LifeCycle Demo App
 
KOIN for dependency Injection
KOIN for dependency InjectionKOIN for dependency Injection
KOIN for dependency Injection
 
ASP.NET Page life cycle and ViewState
ASP.NET Page life cycle and ViewStateASP.NET Page life cycle and ViewState
ASP.NET Page life cycle and ViewState
 
Get started with meteor | designveloper software agency meteor prime partner
Get started with meteor | designveloper software agency   meteor prime partnerGet started with meteor | designveloper software agency   meteor prime partner
Get started with meteor | designveloper software agency meteor prime partner
 
Spring boot Introduction
Spring boot IntroductionSpring boot Introduction
Spring boot Introduction
 
Migration from vaadin 6 to vaadin 7 devoxx france 2013
Migration from vaadin 6 to vaadin 7   devoxx france 2013Migration from vaadin 6 to vaadin 7   devoxx france 2013
Migration from vaadin 6 to vaadin 7 devoxx france 2013
 

Similar to Chapter 03: Eclipse Vert.x - HTTP Based Microservices

maven-for-maine-jug-090226091601-phpapp02.ppt
maven-for-maine-jug-090226091601-phpapp02.pptmaven-for-maine-jug-090226091601-phpapp02.ppt
maven-for-maine-jug-090226091601-phpapp02.pptnikhilmahendranath1
 
Struts tutorial
Struts tutorialStruts tutorial
Struts tutorialOPENLANE
 
B14870 solution final
B14870 solution finalB14870 solution final
B14870 solution finalssuser8f0495
 
Fundamental Concepts of React JS for Beginners.pdf
Fundamental Concepts of React JS for Beginners.pdfFundamental Concepts of React JS for Beginners.pdf
Fundamental Concepts of React JS for Beginners.pdfStephieJohn
 
M2ModuleDevelopmenteBook
M2ModuleDevelopmenteBookM2ModuleDevelopmenteBook
M2ModuleDevelopmenteBookTrọng Huỳnh
 
Implementation of Push Notification in React Native Android app using Firebas...
Implementation of Push Notification in React Native Android app using Firebas...Implementation of Push Notification in React Native Android app using Firebas...
Implementation of Push Notification in React Native Android app using Firebas...naseeb20
 
Rest web service_with_spring_hateoas
Rest web service_with_spring_hateoasRest web service_with_spring_hateoas
Rest web service_with_spring_hateoasZeid Hassan
 
LearningMVCWithLINQToSQL
LearningMVCWithLINQToSQLLearningMVCWithLINQToSQL
LearningMVCWithLINQToSQLAkhil Mittal
 
Aspnet mvc tutorial_01_cs
Aspnet mvc tutorial_01_csAspnet mvc tutorial_01_cs
Aspnet mvc tutorial_01_csAlfa Gama Omega
 
A Java Microservices Spring Boot and Docker case study.
A Java Microservices Spring Boot and Docker case study.A Java Microservices Spring Boot and Docker case study.
A Java Microservices Spring Boot and Docker case study.Subramanyam Vemala
 
Fundamental concepts of react js
Fundamental concepts of react jsFundamental concepts of react js
Fundamental concepts of react jsStephieJohn
 
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 desaijinaldesailive
 
Java microservicesdockerdockerhubusecase2
Java microservicesdockerdockerhubusecase2Java microservicesdockerdockerhubusecase2
Java microservicesdockerdockerhubusecase2Subramanyam Vemala
 
Meteor.js Workshop by Dopravo
Meteor.js Workshop by DopravoMeteor.js Workshop by Dopravo
Meteor.js Workshop by DopravoArabNet ME
 

Similar to Chapter 03: Eclipse Vert.x - HTTP Based Microservices (20)

Chapter 04: Eclipse Vert.x - Message Based Microservices
Chapter 04: Eclipse Vert.x - Message Based MicroservicesChapter 04: Eclipse Vert.x - Message Based Microservices
Chapter 04: Eclipse Vert.x - Message Based Microservices
 
maven-for-maine-jug-090226091601-phpapp02.ppt
maven-for-maine-jug-090226091601-phpapp02.pptmaven-for-maine-jug-090226091601-phpapp02.ppt
maven-for-maine-jug-090226091601-phpapp02.ppt
 
Meteor
MeteorMeteor
Meteor
 
Struts tutorial
Struts tutorialStruts tutorial
Struts tutorial
 
B14870 solution final
B14870 solution finalB14870 solution final
B14870 solution final
 
Servlets
ServletsServlets
Servlets
 
Fundamental Concepts of React JS for Beginners.pdf
Fundamental Concepts of React JS for Beginners.pdfFundamental Concepts of React JS for Beginners.pdf
Fundamental Concepts of React JS for Beginners.pdf
 
M2ModuleDevelopmenteBook
M2ModuleDevelopmenteBookM2ModuleDevelopmenteBook
M2ModuleDevelopmenteBook
 
Implementation of Push Notification in React Native Android app using Firebas...
Implementation of Push Notification in React Native Android app using Firebas...Implementation of Push Notification in React Native Android app using Firebas...
Implementation of Push Notification in React Native Android app using Firebas...
 
Building richwebapplicationsusingasp
Building richwebapplicationsusingaspBuilding richwebapplicationsusingasp
Building richwebapplicationsusingasp
 
Rest web service_with_spring_hateoas
Rest web service_with_spring_hateoasRest web service_with_spring_hateoas
Rest web service_with_spring_hateoas
 
LearningMVCWithLINQToSQL
LearningMVCWithLINQToSQLLearningMVCWithLINQToSQL
LearningMVCWithLINQToSQL
 
React js
React jsReact js
React js
 
Aspnet mvc tutorial_01_cs
Aspnet mvc tutorial_01_csAspnet mvc tutorial_01_cs
Aspnet mvc tutorial_01_cs
 
A Java Microservices Spring Boot and Docker case study.
A Java Microservices Spring Boot and Docker case study.A Java Microservices Spring Boot and Docker case study.
A Java Microservices Spring Boot and Docker case study.
 
Fundamental concepts of react js
Fundamental concepts of react jsFundamental concepts of react js
Fundamental concepts of react js
 
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
 
Java microservicesdockerdockerhubusecase2
Java microservicesdockerdockerhubusecase2Java microservicesdockerdockerhubusecase2
Java microservicesdockerdockerhubusecase2
 
Jdbc
JdbcJdbc
Jdbc
 
Meteor.js Workshop by Dopravo
Meteor.js Workshop by DopravoMeteor.js Workshop by Dopravo
Meteor.js Workshop by Dopravo
 

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

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

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 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
 
Chapter 05: Eclipse Vert.x - Service Discovery, Resilience and Stability Patt...
Chapter 05: Eclipse Vert.x - Service Discovery, Resilience and Stability Patt...Chapter 05: Eclipse Vert.x - Service Discovery, Resilience and Stability Patt...
Chapter 05: Eclipse Vert.x - Service Discovery, Resilience and Stability Patt...
 
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

GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptkotipi9215
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
software engineering Chapter 5 System modeling.pptx
software engineering Chapter 5 System modeling.pptxsoftware engineering Chapter 5 System modeling.pptx
software engineering Chapter 5 System modeling.pptxnada99848
 

Recently uploaded (20)

GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.ppt
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
software engineering Chapter 5 System modeling.pptx
software engineering Chapter 5 System modeling.pptxsoftware engineering Chapter 5 System modeling.pptx
software engineering Chapter 5 System modeling.pptx
 

Chapter 03: Eclipse Vert.x - HTTP Based Microservices

  • 2. 00. Sequence Diagram We will create two verticle classes with following sequence diagram to demonstrate HTTP based Microservices HttpMicro02 HttpMicro01 HTTP Request HTTP Request /Firmansyah HTTP Request /Indonesia HTTP Response “hello Firmansyah” HTTP Response “hello Indonesia” HTTP Response
  • 3. 01. Create HttpMicro01 Class a. Create a directory called “chapter03” b. Generate the project structure using maven inside chapter03 folder: mvn io.fabric8:vertx-maven-plugin:1.0.5:setup -DprojectGroupId=io.vertx.chapter03 -DprojectArtifactId=http-micro-vertx-app -Dverticle=io.vertx.chapter03.HttpMicro01 -Ddependencies=web This command generates: 1. The Maven project structure, 2. Configures the vertx-maven-plugin, and 3. Creates a verticle class (io.vertx.chapter03.HttpMicro01), 4. Adds the vertx-web dependency, Vert.x Web is a module that provides everything you need to build modern web applications on top of Vert.x.
  • 4. 01. Create HttpMicro01 Class c. Modify io.vertx.chapter03.HttpMicro01 Class 1. Create method for JSON HTTP response (Vert.x provides a JsonObject class to create and manipulate JSON structures.): private void helloJson(RoutingContext rc) { String message = "hello"; if (rc.pathParam("name") != null) { message += " " + rc.pathParam("name"); } JsonObject json = new JsonObject().put("message", message); rc.response() .putHeader(HttpHeaders.CONTENT_TYPE, "application/json") .end(json.encode()); } 2. Add logic for HTTP Server creation, routes and parameters request handling inside the start() method:
  • 5. 01. Create HttpMicro01 Class public void start() { Router router = Router.router(vertx); router.get("/").handler(this::helloJson); router.get("/:name").handler(this::helloJson); vertx.createHttpServer() .requestHandler(router::accept) .listen(8080); } Notes: • This code creates an HTTP server on port 8080 and registers a requestHandler and use the accept method of the router. • Vert.x Web provides a Router on which we can register Routes. Routes are the mechanism by which Vert.x Web checks the path and invokes the associated action. • Once we have created the Router object, we register two routes. The first one handles requests on / and just writes hello. The second route has a path parameter (:name). The handler will call helloJson to return JSON response
  • 6. 01. Create HttpMicro01 Class d. Package app as a fat jar, launch: mvn clean package e. Run this application, launch: java -jar target/http-micro-vertx-app-1.0-SNAPSHOT.jar f. Browse URL http://localhost:8080/ and look at the application output. g. Use Ctrl + C to shut down.
  • 7. 02. Create HttpMicro02 Class a. Create a directory called “consumer” inside chapter03 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.chapter03 -DprojectArtifactId=http-micro02-vertx-app -Dverticle=io.vertx.chapter03.HttpMicro02 -Ddependencies=web,web-client,rx Notes: 1. The last command adds another dependency: the Vert.x web client, an asynchronous HTTP client. We will use this client to call the first microservice (HttpMicro01 class). 2. The command has also added the Vert.x RxJava binding.
  • 8. 02. Create HttpMicro02 Class c. Modify io.vertx.chapter03.HttpMicro02 1. In the start method, we create a WebClient and a Router. 2. On the created router, we register a route on “/” and start the HTTP server, passing the router accept method as requestHandler. 3. The handler of the route is a method invokeHttpMicro01() with following logic: • Uses the web client to invoke the first microservice with a specific path (/firmansyah) • The handler we passed in into request.send() is invoked when either the response arrives or an error occurs. • When it succeeds, we write the received payload to the response; otherwise, we reply with a 500 response
  • 9. Thank You! Any questions? You can find me at firmansyah.profess@gmail.com Credits PPT: ALLPPT.com Music: https://www.bensound.com