Blogg
Här finns tekniska artiklar, presentationer och nyheter om arkitektur och systemutveckling. Håll dig uppdaterad, följ oss på LinkedIn
Här finns tekniska artiklar, presentationer och nyheter om arkitektur och systemutveckling. Håll dig uppdaterad, följ oss på LinkedIn
The 2nd edition contains many updates using the latest versions of the tools and frameworks covered by the book. It also includes two major additions: support for Windows using WSL 2 and compiling Java-based microservices to native images using Spring Native and GraalVM. In this blog post, I will go through the most significant changes and news.
Since the 1st edition was published in September 2019, a lot of exciting new versions have been released by the open source projects used in the book. Last autumn, my publisher asked me if I was interested in producing an updated version of the book. On July 29th, the 2nd edition of my book was published:
If you are interested in a complete overview of the content in the book, I will cover that in a few blog posts as well, here is part 1 for now.
Let’s start looking at the new support for Windows using WSL 2 and native compile:
Support for Windows 10 and WSL 2
The 1st edition only describes how to run the examples in the book on a Mac. One of the main goals of the 2nd edition was to add support for running the examples on a Windows PC. To run the same commands as used on a Mac, Windows Subsystem for Linux v2 (WSL 2) is used to run a Linux server on the Windows PC. All commands for building, running, and testing the microservices are executed on the Linux server using Windows Terminal. Tools that require a user interface, like an IDE (Visual Studio Code) and a Web Browser, run in Windows. Docker runs in a separate WSL 2 instance, reachable from both Windows and the Linux server.
The following screenshot demonstrates how the microservices are deployed in Kubernetes using Minikube in WSL 2. Windows Terminal is used to run a load test and check the status of the Pods in Kubernetes. The source code is edited in Visual Studio Code using its Remote WSL extension, and the traffic that flows through the microservices is monitored in a Web Browser using Istio and Kiali also deployed in Kubernetes:
Compiling Java-based microservices to native images
The second main goal of the 2nd edition was to describe how we can use the emerging technology for compiling Java-based microservices to native images. Thus, the book’s last chapter explains how to use the current beta version of Spring Native and the underlying GraalVM to compile a microservice into a Docker image containing a native executable. One of the main benefits of a native image is a dramatically reduced startup time compared to using the Java VM. However, it comes at the price of a long compile-time. Furthermore, since Spring Native is still in beta, not all tools and frameworks in the Spring ecosystem are fully supported. But this is an exciting technology to keep an eye on for the future.
Below is an example where a microservice from the book compiled to a native image starts in 0.644 seconds. To compare, starting up the microservice using the Java VM takes around 13 seconds in the same environment, 20 times slower!
Besides these two additions, the most important news and changes are:
Upgraded to Spring Boot v2.5.2 and Spring Cloud 2020.0.3
The 2nd edition is updated to use new features introduced in Spring Boot v2.3 - v2.5, for example:
spring.profiles
property has been replaced with the new spring.config.activate.on-profile
property.spring.config.import
is used to import files from the Spring Cloud Config Server.layered jars
instead of the traditional fat-jar
using Spring Boot’s layer extraction tool.Finally, regarding Spring Boot, the reactive parts of the source code have been both simplified and more robust. For Spring Cloud Stream, the functional and reactive programming model introduced in v3.0.0 has been applied when interacting with message brokers, i.e. RabbitMQ and Kafka. This means, for example, that Java’s functional interface Consumer
is used to declare consumers of the events published through a message broker.
Upgraded to Java 16 and Gradle 7.
Since many Java developers still use Java 8 (including most of the customers I work with), all source code is written using Java 8 syntax. But in runtime, a Java 16 JRE is used.
Using Testcontainers instead of embedded databases for integration tests
With Testcontainers, the same database engines used in production can be used when running integration tests with JUnit.
Upgraded to JUnit 5
Replaced SpringFox with springdoc-openapi for producing OpenAPI documentation on the fly
The SpringFox project is no longer actively maintained, and the migration to the springdoc-openapi project is a no-brainer.
Replaced the authorization server from the deprecated Spring Security OAuth project with Spring Authorization Server
Updated usage of OAuth to be compliant with the upcoming OAuth 2.1 specification
No more usage of Implicit and Resource Owner Password Credentials grant flows.
Simplified setup of the OIDC provider in Auth0
The central part of the configuration required for the Auth0 account is automated.
Upgraded to Resilience4j 1.7.0
Older versions of Resilience4j do not work with Spring Boot using version 2.4 or newer.
Upgraded to Minikube 1.18.1
The driver for VirtualBox is replaced with the driver for HyperKit on macOS and the Docker-driver on Windows/WSL2. This results in faster startup times for the Kubernetes clusters and overall lower resource usage.
Upgraded to Kubernetes to 1.20.5
Simplified use of the cert-manager
for automated issuing and provisioning of certificates. Using self-signed certificates instead of the cumbersome setup of ngrok
and Let's Encrypt
in a development environment (with no fixed and public IP address).
Replaced Kustomize with Helm 3 to configure the deployments in Kubernetes
Common boilerplate definitions in the Kubernetes yaml
files have been extracted using Helm library
charts. The microservices have their own chart definition. Each runtime environment is defined in a parent chart
, where the microservices’ charts are used as subcharts
to describe the runtime components in each environment’s system landscape.
cert-manager
to issue and provision certificates.v1apltha1
security policy APIs, removed in Istio v1.6, with the corresponding new APIs.Upgraded to Elastic and Kibana 7.12.1
Writing a book based on the latest versions of open source projects is asking for trouble. It is inevitable to be exposed to regressions in existing functionality and new features that don’t fully work as intended. During the development of this book, I reported several issues on GitHub and participated in several discussions on Stack Overflow to get various problems resolved. I want to thank the open-source community for helping me resolving, among others, the following issues: