Reader small image

You're reading from  Hands-On Enterprise Java Microservices with Eclipse MicroProfile

Product typeBook
Published inAug 2019
Reading LevelExpert
PublisherPackt
ISBN-139781838643102
Edition1st Edition
Languages
Right arrow
Authors (6):
Cesar Saavedra
Cesar Saavedra
author image
Cesar Saavedra

Cesar Saavedra has been working in the IT industry since 1990 and holds a Master of Science degree in Computer Science and a Master of Business Administration. He has worked as a developer, consultant, technical seller, and technical marketer throughout his career. He currently does technical product marketing for Red Hat JBoss Enterprise Application Platform (EAP), Eclipse MicroProfile, OpenJDK, Quarkus and Jakarta EE. He also manages the technical marketing for the runtimes, integration, BPM and rules management portfolio, and works closely with engineering and product management on thought leadership. Cesar has authored white papers, eBooks, and blogposts, and has been a conference and webinar speaker presenting to customers and partners.
Read more about Cesar Saavedra

Heiko W. Rupp
Heiko W. Rupp
author image
Heiko W. Rupp

Heiko W. Rupp is an open source enthusiast working for more than a decade at Red Hat in the area of middleware monitoring and management. In this role he has been project lead of the RHQ and Hawkular monitoring systems and has also been contributing to various other projects like Kiali. Currently he helps defining the next way of Java Microservices with his work on Eclipse MicroProfile. As such he is the spec lead of the Eclipse MicroProfile Metrics effort and also contributing to other specifications. Heiko has written the first German book about JBossAS and one of the first German books on EJB3. He lives with his family in Stuttgart, Germany.
Read more about Heiko W. Rupp

Jeff Mesnil
Jeff Mesnil
author image
Jeff Mesnil

Jeff Mesnil is employed by Red Hat as a Senior Software Engineer and currently, works for JBoss, Red Hat's middleware division, on the WildFly and JBoss EAP application servers. He is a member of the core team in charge of developing the internals of the application servers and lead its messaging subsystem (which provides the JMS API). Previously, he contributed to the HornetQ messaging broker that was integrated into WildFly and EAP. He is a proponent of Open Source development and all the code he writes either professionally or privately is available under Open Source licenses, these days, it is mostly hosted on GitHub. He has a keen interest on messaging systems and wrote several Open Source libraries related to messaging.
Read more about Jeff Mesnil

Pavol Loffay
Pavol Loffay
author image
Pavol Loffay

Pavol Loffay is Senior Software Engineer at Red Hat. Pavol is working on observability tools for microservice architectures. He is mostly involved in the tracing domain, where he is an active committer on the Jaeger and OpenTracing projects. He is also a member of the OpenTracing Specification Council (OTSC) and a lead for the MicroProfile-OpenTracing specification. He has authored many blog posts and presented at several conferences. In his free time, Pavol likes to climb mountains and ski steep slopes in the Alps.
Read more about Pavol Loffay

Antoine Sabot-Durand
Antoine Sabot-Durand
author image
Antoine Sabot-Durand

Antoine Sabot-Durand is a Java Champion who works for Red Hat where he leads the Java EE, now Jakarta EE CDI spec. He is also involved in various projects linked to the CDI ecosystem, MicroProfile, and Jakarta EE. He is also Member of Devoxx France committee. He lives in France with his wife and 3 kids.
Read more about Antoine Sabot-Durand

Scott Stark
Scott Stark
author image
Scott Stark

Scott Stark started in chemical engineering, got steered into parallel computers as part of his Ph.D. work, and then made software his career, starting with a stint in finance/wall street. He then got into open source with the fledgling JBoss company, working on the application server and Java EE. He has worked with microkernel efforts, IoT efforts, standards, Jakarta EE, Eclipse MicroProfile and Quarkus. He lives in the Pacific Northwest with his wife.
Read more about Scott Stark

View More author details
Right arrow

A Working Eclipse MicroProfile Code Sample

In this chapter, we will discuss a sample application that makes use of the various MicroProfile features introduced earlier in this book. The MicroProfile runtime we will use in this chapter is the Quarkus runtime, a Kubernetes-native Java stack tailored for GraalVM and OpenJDK HotSpot, crafted from best of breed Java libraries and standards. Key topics that we will cover include the following:

  • Use of configuration for both application and MicroProfile container behaviors
  • Realistic health checks
  • Securing an application with an external JWT security provider
  • Integrating and viewing trace information with a Jaeger instance
  • Inspecting microservice endpoint information using Swagger
  • Viewing individual and complete application metrics
  • Accessing both intra-cloud and external microservices using the rest client

The purpose of these topics...

Technical requirements

For this chapter, we'll require the following:

  • An IDE
  • JDK 1.8+ installed with JAVA_HOME configured appropriately
  • Apache Maven 3.5.3+
  • A running Docker environment

The code for this chapter can be found at https://github.com/PacktPublishing/Hands-On-Enterprise-Java-Microservices-with-Eclipse-MicroProfile/tree/master/Chapter08-mpcodesample.

The sample in this chapter can be compiled into a native binary using the GraalVM (https://github.com/oracle/graal/releases/tag/vm-1.0.0-rc16) integration of Quarkus. This has additional requirements for the installation of the 1.0-RC16 version Graal VM and a working C development environment. The details of the native image generation requirements can be found at https://quarkus.io/guides/building-native-image-guide.

Sample architecture of a multiservice MicroProfile application

The sample application we will go over in this chapter is composed of an HTML frontend, two MicroProfile-based microservices, two external services we spin up using Docker, and an external time service on the web we have no control over. The architecture of our sample application is shown in the following diagram:

The key elements in this diagram include the following:

  • Svcs1 Image: This is a collection of REST endpoints that make use of MP-HC, MP-Metrics, MP-OT, MP-JWT, MP-OAPI, MP-FT, and MP-RC in a Quarkus runtime.
  • Svcs2 Image: This is a collection of REST endpoints that make use of MP-HC and MP-Metrics in a Quarkus runtime.
  • Jaeger: This a Docker image that runs the Jaeger server for the collection of trace loggings.
  • KeyCloak: This is a Docker image that runs a KeyCloak 6.0.0 server instance.
  • WorldClock: This is...

Summary

This chapter has walked us through a sample service mesh composed of a web application, two microservice images using MP features in a new Quarkus implementation, an external web service, and two Docker-based services. This showed the interplay between the various MP features and external services you will find in cloud environments, along with integration with web services external to the local mesh environment. This should give you a feeling of the steps involved when composing microservices using the MicroProfile APIs and implementations.

In the next chapter, we will take a look at MicroProfile specifications that are under development to have an idea of what directions are being explored. While these specifications are currently outside of the MicroProfile core feature set, they are candidates for future inclusion, and looking at them will give us an idea of where...

Questions

  1. Do the MP-Config settings affect application code, MP feature code, or both?
  2. Were you able to update health.pathToMonitor to a valid path and see an updated health status reply?
  3. What does the Svcs2 health status link (http://localhost:8082/health) on the Health tab show as its output? If you stop the KeyCloak Docker image and click on the link again, does the output change?
  4. What happens if you select the MetricController.timed-request link (http://localhost:8080/metrics/application/io.packt.sample.metric.MetricController.timed-request) in the Metrics tab without first hitting the Timed endpoint link (http://localhost:8080/demo1/metric/timed) at least once?
  5. Go to the RestClient tab and hit the link, making sure you have a valid JWT. Next, go to the OpenTracing tab and open the Jaeger UI, and pull up the current traces by clicking the Find Traces button. You should see...

Further reading

Going over the code, trying changes, and then interacting with the updated code is a good way to understand more of the details behind the sample services. The Quarkus MicroProfile implementation supports live reload features that allow you to make changes without having to rebuild. For more information on this topic, see Maven Tooling (https://quarkus.io/guides/maven-tooling.html) on the Quarkus site.

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Hands-On Enterprise Java Microservices with Eclipse MicroProfile
Published in: Aug 2019Publisher: PacktISBN-13: 9781838643102
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Authors (6)

author image
Cesar Saavedra

Cesar Saavedra has been working in the IT industry since 1990 and holds a Master of Science degree in Computer Science and a Master of Business Administration. He has worked as a developer, consultant, technical seller, and technical marketer throughout his career. He currently does technical product marketing for Red Hat JBoss Enterprise Application Platform (EAP), Eclipse MicroProfile, OpenJDK, Quarkus and Jakarta EE. He also manages the technical marketing for the runtimes, integration, BPM and rules management portfolio, and works closely with engineering and product management on thought leadership. Cesar has authored white papers, eBooks, and blogposts, and has been a conference and webinar speaker presenting to customers and partners.
Read more about Cesar Saavedra

author image
Heiko W. Rupp

Heiko W. Rupp is an open source enthusiast working for more than a decade at Red Hat in the area of middleware monitoring and management. In this role he has been project lead of the RHQ and Hawkular monitoring systems and has also been contributing to various other projects like Kiali. Currently he helps defining the next way of Java Microservices with his work on Eclipse MicroProfile. As such he is the spec lead of the Eclipse MicroProfile Metrics effort and also contributing to other specifications. Heiko has written the first German book about JBossAS and one of the first German books on EJB3. He lives with his family in Stuttgart, Germany.
Read more about Heiko W. Rupp

author image
Jeff Mesnil

Jeff Mesnil is employed by Red Hat as a Senior Software Engineer and currently, works for JBoss, Red Hat's middleware division, on the WildFly and JBoss EAP application servers. He is a member of the core team in charge of developing the internals of the application servers and lead its messaging subsystem (which provides the JMS API). Previously, he contributed to the HornetQ messaging broker that was integrated into WildFly and EAP. He is a proponent of Open Source development and all the code he writes either professionally or privately is available under Open Source licenses, these days, it is mostly hosted on GitHub. He has a keen interest on messaging systems and wrote several Open Source libraries related to messaging.
Read more about Jeff Mesnil

author image
Pavol Loffay

Pavol Loffay is Senior Software Engineer at Red Hat. Pavol is working on observability tools for microservice architectures. He is mostly involved in the tracing domain, where he is an active committer on the Jaeger and OpenTracing projects. He is also a member of the OpenTracing Specification Council (OTSC) and a lead for the MicroProfile-OpenTracing specification. He has authored many blog posts and presented at several conferences. In his free time, Pavol likes to climb mountains and ski steep slopes in the Alps.
Read more about Pavol Loffay

author image
Antoine Sabot-Durand

Antoine Sabot-Durand is a Java Champion who works for Red Hat where he leads the Java EE, now Jakarta EE CDI spec. He is also involved in various projects linked to the CDI ecosystem, MicroProfile, and Jakarta EE. He is also Member of Devoxx France committee. He lives in France with his wife and 3 kids.
Read more about Antoine Sabot-Durand

author image
Scott Stark

Scott Stark started in chemical engineering, got steered into parallel computers as part of his Ph.D. work, and then made software his career, starting with a stint in finance/wall street. He then got into open source with the fledgling JBoss company, working on the application server and Java EE. He has worked with microkernel efforts, IoT efforts, standards, Jakarta EE, Eclipse MicroProfile and Quarkus. He lives in the Pacific Northwest with his wife.
Read more about Scott Stark