Start United States USA — software Buiding Microservices Using Spring Boot and Docker – Part 1

Buiding Microservices Using Spring Boot and Docker – Part 1

449
0
TEILEN

In this tutorial, learn how to build microservices using Spring Boot and its different components, and how to deploy your microservices using Docker containers.
In this tutorial, I will show you how to build microservices using Spring Boot and its different components, and in the last section, I will show you the deployment using Docker containers.
Implementing different components of Microservices.
Deployment of services through containerization.
Before starting, I will just touch base on the important components of microservice architecture.
While implementing Microservices, the following components are the pillar of the architecture:
Now we have a basic understanding how different parts of a microservice work together. In this tutorial, I will create an employee search service which will return employee information, an EmployeeDashBoard Service which will invoke the search service and show the results, a Eureka server so that these services can register themselves, and a gateway service to reach out to these services from outside. Then we will deploy our services in docker container and use DockerCompose to spawn the Docker containers. I will use Spring Boot for this tutorial.
Let’s start to build our microservice project, as we have to create five individual services:
1. Config Server
2. Eureka server
3. Employee service
4. Employee Dashboard service
5. Zuul Proxy
The best place to start is going to http://start.spring.io/ ., shopping the requires modules, and hitting „generate project.“
For this tutorial, we will use Spring Boot 1.5.4.
To create the config server, first we need to check the config server module from starts.spring.io, and also check the actuator to see the endpoints. Then, download the zip file and open it in Eclipse.
It downloads the spring-cloud-config-server artifacts.
Next, we have to create a bootstrap.properties file where we mention from which location the config server reads the property. In production mode, it should be the URL of the Git repository, but as this is a demo, I’ll use my local disk. All properties files will be placed there, and the config server reads those property files.
Here, I instruct Spring Boot to spawn the embedded server in port 9090 and use a centralProperties folder as a folder to search all properties files. Note that in our Docker container, you have to create a central properties folder and place all the properties files there.
Now let’s see the Java part:
Here I use the @EnableConfigserver annotation, with which we instruct Spring Boot to consider this service as a config server application.
Now place few test properties files in centralProperties folder.
We are all set for the config server now. If we run this service and hit the http://localhost:9090/config/default URL, we see the following response:
It shows the all file names and key and values I placed in the centralProperties folder.
The next step is to create a Eureka server for service discovery.
The pom.xml looks like this:
Now create the bootstrap.properties:
Now I will create the Java file:
With the @EnableEurekaServer annotation, Spring Boot spawns this service as Eureka server. We are all set now; if I run the service and hit the http://localhost:9091/ in the browser, we will see the following screen:
In Part 2, we will create the Employee Search and other services, then learn about deploying your microservices with Docker. Stay tuned!

Continue reading...