Book Image

Building Microservices with Micronaut®

By : Nirmal Singh, Zack Dawood
Book Image

Building Microservices with Micronaut®

By: Nirmal Singh, Zack Dawood

Overview of this book

The open source Micronaut® framework is a JVM-based toolkit designed to create microservices quickly and easily. This book will help full-stack and Java developers build modular, high-performing, and reactive microservice-based apps using the Micronaut framework. You'll start by building microservices and learning about the core components, such as ahead-of-time compilation, reflection-less dependency injection, and reactive baked-in HTTP clients and servers. Next, you will work on a real-time microservice application and learn how to integrate Micronaut projects with different kinds of relational and non-relational databases. You'll also learn how to employ different security mechanisms to safeguard your microservices and integrate microservices using event-driven architecture in the Apache Kafka ecosystem. As you advance, you'll get to grips with automated testing and popular testing tools. The book will help you understand how you can easily handle microservice concerns in Micronaut projects, such as service discovery, API documentation, distributed configuration management, fallbacks, and circuit breakers. Finally, you'll explore the deployment and maintenance aspects of microservices and get up to speed with the Internet of Things (IoT) using the Framework. By the end of this book, you'll be able to build, test, deploy, and maintain your own microservice apps using the framework.
Table of Contents (20 chapters)
1
Section 1: Core Concepts and Basics
3
Section 2: Microservices Development
8
Section 3: Microservices Testing
10
Section 4: Microservices Deployment
13
Section 5: Microservices Maintenance
15
Section 6: IoT with Micronaut and Closure

Using JWT authentication to secure the service endpoints

In token-based authentication, the user state is stored at the client side. When a client logs in to the server, the server encrypts the user data into a token with a secret and sends it back to the client. Any subsequent user requests must have this token set in the request header. The server retrieves the token, validates the authenticity, and resumes the user session:

Figure 4.9 – Token-based authentication

As shown in the preceding diagram, in a token-based authentication strategy, the client does the heavy lifting of keeping track of the session in the JSON web token. A client must provide a valid token to resume the session.

To learn how to secure a microservice using token-based authentication, we will work on a hands-on pet-clinic microservice. To begin, we will set up a third-party identity provider using Keycloak. In the next section, we will set up Keycloak locally.

Setting up...