Microservices Architecture (MSA)
Today we are going to talk about Domain Driven Design (DDD) and microservices with Spring and Java +8. This article is intended as a beginner’s kit where you will find:
- DDD View
- Spring and springboot with main examples and annotations
- Spring core on main examples and annotations
- Spring data, patterns and some utilities:
To facilitate the follow-up of this entry, we have prepared a PDF file with the contents:
Having said that, let’s see the tools and technologies that will be used for the Product’s environment:
|https://spring.io/tools||Spring Tools 4 for Eclipse||Spring Tool Suite is an Eclipse-based development environment that is modified to develop Spring applications.|
|Maven||https://maven.apache.org/||Maven 3.5 or higher||Apache Maven is a tool for managing and understanding a software project.|
|Git / Gitlab||https://about.gitlab.com/||–||Gitlab is a Git-based web service for version control and collaborative development.|
|Sourcetree||https://www.sourcetreeapp.com/||Sourcetree 3 or higher||Sourcetree is a Git-based GUI that provides a visual representation of your repositories. Sourcetree is a free Git client for Windows and Mac.|
|Junit||https://junit.org/junit5/||Junit 5 or higher||JUnit is an open-source framework for the purpose of writing and running tests in the Java programming language (Implemented with Mockito 2.X https://site.mockito.org/). Maven Plugins: JaCoCo Maven plug-in provides the JaCoCo runtime agent to your tests and allows the creation of basic reports.|
|Sonarqube||https://www.sonarqube.org/||Sonarqube 7 or higher||Sonarqube is an open-source platform developed by SonarSource for continuous code quality inspection to perform automatic reviews with static code analysis to detect bugs, code smells, and security vulnerabilities.|
|Jenkins||https://jenkins.io/||Jenkins 2 or higher||Jenkins is an open-source automated server written in Java. Jenkins helps automate the non-human part of the software development process, with continuous integration and making the technical aspects of continuous delivery easier.|
|Nexus||https://www.sonatype.com/nexus-repository-sonatype||Nexus 3 or higher||Nexus is a repository manager. It allows you to collect and manage your dependencies so you don’t have to constantly shuffle through a collection of JARs. It makes it easier to distribute your software. Internally, you configure your build to publish artifacts to the Nexus and then make them available to other developers.|
|OpenJDK||https://adoptopenjdk.net/||Openjdk 8.X||OpenJDK is the free version of the Java development platform under the object-oriented language concept.|
|Spring Framework||https://spring.io/||Spring 5.X||Spring Framework is an application framework and inversion of control wrapper for the Java platform. The core features of the framework can be used by any Java application, but there are extensions for building web applications on top of the Java EE (Enterprise Edition) platform.|
|Spring-Boot||https://spring.io/projects/spring-boot||Spring-Boot 2.X||Spring Boot was designed to simplify the bootstrapping and development of new Spring applications. The framework takes a dogmatic approach to configuration, freeing developers from the need to define boilerplate configuration.|
|Swagger||https://swagger.io/||Swagger 2.X or higher||Swagger is an open-source software framework, backed by a large ecosystem of tools, that helps developers design, build, document, and consume RESTful web services.|
|Tomcat||http://tomcat.apache.org/||Tomcat 9.X||Apache Tomcat, commonly referred to as Tomcat Server, is an open-source Java Servlet Container developed by the Apache Software Foundation (ASF). Look at Tomcat embedded in Spring Boot.|
|Docker||https://www.docker.com/||Docker 18.X||Docker is a tool designed to make it easy to build, deploy, and run applications using containers. Containers allow a developer to package an application with all the parts it will needs, such as its libraries and other dependencies, and ship everything as a single package.|
|Kubernetes||https://kubernetes.io/||Kubernetes 1.X||Kubernetes (K8s) is an open-source system to automatically deploy, scale, and manage containerized applications.|
|Rancher||https://rancher.com/||Rancher 2.X||Rancher combines everything an organization needs to run containers in production and to centrally manage multiple Kubernetes clusters. Request a demo today!|
|Azure||https://azure.microsoft.com/es-es/||–||Microsoft Azure is a cloud computing service created by Microsoft to build, test, deploy, and manage applications and services through Microsoft data centers.|
|https://onesaitplatform.atlassian.net/||X||Onesait Platform provides flexibility for our clients to build their own solutions in a robust and agile way, using open-source technologies, a flexible architecture, and an innovative approach.|
Microservices in Spring
Currently Spring is an open source framework that facilitates the development of Java JEE & JSE applications. It is made up of multiple modules/projects covering all layers of the application, with dozens of developers and thousands of downloads per day. It provides a container in charge of managing the life cycle of objects (beans) so that developers can focus on business logic. It allows integration with different frameworks. Due to this capacity for modularity and development in different environments, it is optimal for the implementation of microservices.
These microservices are characterized by being:
- Lightweight: the impact of integrating Spring is minimal.
- Non-intrusive: in general, the objects that are programmed do not have dependencies on Spring-specific classes.
- Resilient: although Spring provides functionality to handle the different layers of the application (view, business logic, data access), it is not necessary to use it for everything. It offers the possibility of using it in the layer or layers that we want.
- Cross-platform: written in Java, runs on JVM.
Modules to use
The main modules that are necessary to develop microservices in Spring are Spring Framework, Spring Data, Spring Boot and Spring Security:
- Spring Framework: Provides a comprehensive programming and configuration model for modern Java-based enterprise applications, on any type of deployment platform. A key element of Spring is the application-level infrastructure support: it focuses on communications between the storage, system, and network layers of enterprise applications so that teams can focus on business logic at the application level, without unnecessary links to specific deployment environments.
- Spring Boot: it is a tool that was born with the purpose of simplifying the development of applications based on the Spring Core framework: the developer only focuses on the development of the solution, completely forgetting about the complex configuration that Spring Core currently has for be able to function, especially by providing a quick start with less coding.
- Spring Data: is a SpringSource project (subprojects) whose purpose is to unify and facilitate access to different types of persistence technologies, both relational and NoSQL-type databases. It comes to cover the necessary support for different NoSQL database technologies, integrating them with traditional data access technologies, thus simplifying the work when creating specific implementations.
Normally it uses a repository class that acts as a mediator between the application domain and the data that gives it persistence. The repetitive task of creating the concrete DAO implementations for the entities is simplified, because only one interface is needed, and provided.
- Spring Security: this module provides Spring with a number of applicable security services for systems based on the J2EE-based architecture. The security processes are mainly intended to verify the identity of the user through authentication and the permissions associated with it through authorization. The authorization is dependent on the authentication, since it occurs after its process.
Summary of frequent IoC annotations
- Self-discovery: categorize each one of the components, associating them with a specific responsibility: @Scope, @Component, @Repository, @Service, @Controller.
- Customization: @Configuration, @Bean.
- Injection: by default the injection is mandatory. It can be marked as optional in which case, should the Bean be not found, a null will be injected: @Autowire (@Inject), @Qualifier (@Named), @Value, @PropertySource, @Required, @ Resource.
- JPA: @Entity, @Table (applies to a class), @Id, @column, @Transient (applies to Java properties).
- Others: @PostConstruct, @PreDestroy.
You can find more information about it on the Spring website, as well as on the Lombok plugin website.