Basic architecture framework to create complete microservices using Spring boot and Spring cloud
Basic architecture framework to create complete microservices using Spring boot and Spring cloud
This repository is an example of how to get Microservices going using Spring Boot, Spring Cloud, Spring OAuth 2 and Netflix OSS frameworks.
It also builds on distributed system concepts and tries to provide solutions for common distributed system problem using implementations for circuit breakers, consumer driven contracts etc.
The application consists of 9 different services
./build-all-projects.sh on Mac/Linux systems and then going to each individual folder and running the jars using the java -jar build/libs/basic-.jar command.Docker is an open platform for building, shipping and running distributed applications. Follow steps on the site to install docker based on your operating system.
On the mac command prompt, navigate to the root folder of the application (spring-boot-microservices) and run the ./docker-image-all-projects.sh command. This should build all the images and publish them to docker.
Run the individual images as below
We also have a docker-compose file under docker-orchestration/docker-compose folder that can be used to start all the containers together using docker-compose up -d command on the command prompt. The docker-compose file has been updated to start the containers in the correct order. You can similarly stop the containers using docker-compose down command on the command prompt.
You can also use Rancher for orchestrating your containers and managing them. To set up Rancher on your local box and use it to run the containers.
sudo docker run -d --restart=unless-stopped -p 8080:8080 rancher/server:stable command on the command prompt to start the latest stable rancher server.docker-orchestration/rancher folder. For more details on Rancher and how to run the orchestration, please refer to Rancher documentation.Access UI
You should be able to access the web ui from http://localhost:8765/.
The Eureka server is accessible on http://localhost:8761/
gradle wrapper --gradle-version 3.5 before using gradlew../gradlew clean build eclipse which would setup the .classpath accordingly.There is a growing adoption of Microservices in today's world. Numerous SAAS Companies are moving away from building monolithical products and instead adopting Microservices.
In microservices world, a web service or a microservice is the unit of component. This unit of component delivers a complete Business functionality and could rely on other microservices to fulfill the dependent functionality. These microservices are build separately and deployed separately unlike monoliths in which components can be built separately but are deployed together.
Another key aspect of microservices is that the focus of a team building a component now moves away from just delivering that component to running and maintaining that business functionality given by that component.
Due to the ability to build components separately and running them separately means, the notion of centralized control (governance) and data management goes away. Traditionally monoliths were built around a set of set architecture, technology and frameworks. The key architects would decide what tech was used and key DBAs would decide which and how many databases are used. With Microservices, since each component caters to a somewhat complete business functionality, that centralized control by Key Architects and DBAs goes away. Some Components are best built using JEE and RDBMS, for some Real time Data Analytics is the key, they could use Apache Storm and Apache Kafka, for some others R is better fit, for IO Intensive systems may be Node.js and MongoDB works out. Same way User data could now go in NoSQL databases, Transaction data could go in traditional RDBMS, Recommendation systems could use Hive as their Database and so on.
Decentralized Control
Decentalized Data Management
Disclaimer - While Microservices is much talked about these days, make a note Microservices is not a Free lunch. There is an effort and complexity involved to building and running them, but once you do so, the benefits are plentiful.
You can read more about Microservices here - http://martinfowler.com/articles/microservices.html#CharacteristicsOfAMicroserviceArchitecture
Image References from - http://martinfowler.com/articles/microservices.html
Netflix is one of the pioneers behind the Microservices Architecture. Not only have they successfully run Microservices in production, but they have outsourced their battle hardened framework under Netflix Open Source Software Center initiative - http://netflix.github.io/#repo
You will find implementation of numerous of Netflix's Microservices platform pieces here. Here are few for your reference :
Microservices is somewhat like SOA platform, that there are numerous services. Each Service when it comes online registers itself with Service Registry. When some other service wants to communicate with a already registered service, they would ask the Eureka Server the base url for that service. Multiple instances of the same service could register with Eureka, in that case Eureka could help in doing Load Balancing.
A Microservices environment is built to sustain failures of its parts, that is few of its microservices. In order to keep the system going, Netflix introduced a concept of circuit breaker. A Circuit Breaker provides alternative behavior in case certain microservice is gone down. This way the system gracefully switches to fallback behavior until the system recovers, rather than entire system suffering the ripple effects of failed service.
A Microservice environment needs a gateway. A Gateway is the only entity exposed to the outside world, which allows access to Microservices and does more. A Gateway could do
Ribbon is a Load Balancing Client and is meant to work with Eureka Server. Ribbon talks to Eureka server and relies on it to get base url to one of the instances of microservices in question.
Folks who are familiar with Spring frameworks like Spring MVC, know spring is all about Dependency Injection and Configuration Management. While Spring is an excellent framework, it still takes quite some effort to make a Spring MVC project ready for production.
Spring Boot is Spring's approach towards Convention over Configuration. Spring Boot comes with numerous Start Projects, each starter projects provides a set of conventions which ensures you have an opinionated production ready app.
To begin with Spring Boot allows you to write web services with just One or two classes. See the example below
build.gradle
gradle dependency --> compile("org.springframework.boot:spring-boot-starter-web")Application.java
@SpringBootApplication
public class Application{
public static void main(String[] args){
SpringApplication.run(Application.class, args);
}
}UserController.java
@RestController
public class UserController{
@RequestMapping("/")
public User getUser(String id) {
return new User(id,"firstName","lastName");
}
}Build
$>./gradlew clean build
say this Generates app.jarRunning Application
$>java -jar builds/lib/app.jarThe idea is to have multiple projects like above, one for each microservice. Look at the following directories in this repo
No open issues yet, or sync has not completed.