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

Getting started with the Micronaut framework

In order to get started with the Micronaut framework, we will begin by installing the Micronaut CLI on Mac and Windows OS.

Installing the Micronaut CLI on mac OS

On mac OS, we can install the Micronaut CLI in a couple of ways – using SDKMAN!, Homebrew, or MacPorts. In the following sections, we will cover step-by-step instructions to install the Micronaut CLI.

Installing Micronaut using SDKMAN!

Please follow these steps to install the Micronaut CLI using SDKMAN!:

  1. Open Terminal.
  2. If you don't have SDKMAN! installed, take the following steps:

    a. Type or paste the following command:

    curl -s https://get.sdkman.io | bash

    b. Next, type or paste the following command:

    source "$HOME/.sdkman/bin/sdkman-init.sh"
  3. To install the Micronaut CLI, type or paste the following command:
    source sdk install micronaut

    You will observe the following interactions on Terminal while installing the Micronaut CLI:

    Figure 1.5 – Installing Micronaut CLI on mac OS using SDKMAN!

    Figure 1.5 – Installing Micronaut CLI on mac OS using SDKMAN!

  4. If all the preceding steps execute successfully, you can verify the Micronaut CLI installation by running the following command in Terminal:
    mn -version

Installing Micronaut using Homebrew

Please follow these steps to install the Micronaut CLI using MacPorts:

  1. Open Terminal.
  2. If you don't have Homebrew installed, then take the following steps:

    a. Type or paste the following command:

    /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

    b. Next, type or paste the following command:

    brew update 
  3. Type or paste the following command:
     brew install micronaut

    You will observe the following interactions on Terminal while installing the Micronaut CLI:

    Figure 1.6 – Installing the Micronaut CLI on mac OS using HomeBrew

    Figure 1.6 – Installing the Micronaut CLI on mac OS using HomeBrew

  4. If all the preceding steps execute successfully, you can verify the Micronaut CLI installation by hitting the following command in Terminal:
    mn -version

Installing Micronaut using MacPorts

Please follow these steps to install the Micronaut CLI using Homebrew:

  1. If you don't have MacPorts installed, then follow the instructions at https://www.macports.org/install.php.
  2. Open Terminal.
  3. Type or paste the following command:
    sudo port sync
  4. Type or paste the following command:
    sudo port install micronaut

    You will observe the following interactions on Terminal while installing the Micronaut CLI:

    Figure 1.7 – Installing the Micronaut CLI on macOS using MacPorts

    Figure 1.7 – Installing the Micronaut CLI on macOS using MacPorts

  5. If all the preceding steps execute successfully, you can verify the Micronaut CLI installation by hitting the followed command in Terminal:
    mn -version

Installing the Micronaut CLI on Windows

Please follow these steps to install the Micronaut CLI on Windows:

  1. Download the Micronaut CLI binary from the Micronaut download page: https://micronaut.io/download.html.
  2. Unzip the downloaded binary file into a folder on your system. It is better to keep this in a separate folder under a root directory such as C:\Program Files\Micronaut.
  3. Create a new system variable called MICRONAUT_HOME with the preceding directory path. Please note to add this variable under system variables (not user variables).
  4. Then, update your Windows PATH environment variable. You can add a path such as %MICRONAUT_HOME%\bin.
  5. Open Command Prompt or any terminal and type the following command:
    mn

    This will boot up the CLI for the first time by resolving any dependencies.

  6. To test that the CLI is installed properly, type the following command:
    mn – h

    This is what the command outputs:

    Figure 1.8 – Installing the Micronaut CLI on Windows OS

    Figure 1.8 – Installing the Micronaut CLI on Windows OS

  7. You should see all the CLI options after hitting the preceding command.

In this section, we explored different ways to install the Micronaut CLI in Windows and macOS. In order to get hands-on with the Micronaut framework, we will get started with working on a hello world project in the next section.