Microservices-Spring Cloud
The development of Java Web
JSP (JavaServer Pages)
Do you remember what the original java web framework was?
you 're right! Is Jsp + servlet + business logic code.
JSP is responsible for rendering data, and servlet is responsible for providing data and page Jump.
At this time, there was the idea of stratification.
SpringMVC
Then there is the spring MVC architecture based on spring
MVC idea divides an application into three basic parts:Model,View and Controller
The hierarchy of Java Web projects is clearer.
SpringBoot
With the development of the Internet, there are more and more business logic for web development. With the increase of complex configurations, more and more configurations make the springmvc architecture more and more complex and heavier. Therefore, a more convenient architecture was born, which is springboot.
Spring Boot makes it easy to create stand-alone, production-grade Spring based Applications that you can “just run”.
We take an opinionated view of the Spring platform and third-party libraries so you can get started with minimum fuss. Most Spring Boot applications need minimal Spring configuration.
Features
- Create stand-alone Spring applications
- Embed Tomcat, Jetty or Undertow directly (no need to deploy WAR files)
- Provide opinionated ‘starter’ dependencies to simplify your build configuration
- Automatically configure Spring and 3rd party libraries whenever possible
- Provide production-ready features such as metrics, health checks, and externalized configuration
- Absolutely no code generation and no requirement for XML configuration
SpringCloud
With the further development of the Internet, we have entered the era of big data. A single service is no longer enough to support huge traffic and concurrency problems, so microservices appear.
Microservice is not a technology, but an ecology, a distributed system.
Spring Cloud provides tools for developers to quickly build some of the common patterns in distributed systems (e.g. configuration management, service discovery, circuit breakers, intelligent routing, micro-proxy, control bus, one-time tokens, global locks, leadership election, distributed sessions, cluster state). Coordination of distributed systems leads to boiler plate patterns, and using Spring Cloud developers can quickly stand up services and applications that implement those patterns. They will work well in any distributed environment, including the developer’s own laptop, bare metal data centres, and managed platforms such as Cloud Foundry.
Features
Spring Cloud focuses on providing good out of box experience for typical use cases and extensibility mechanism to cover others.
- Distributed/versioned configuration
- Service registration and discovery
- Routing
- Service-to-service calls
- Load balancing
- Circuit Breakers
- Global locks
- Leadership election and cluster state
- Distributed messaging
four major problems of distributed systems
In short, the microservice architecture solves four major problems of distributed systems:
- There are many services. How can clients access them?
- How do so many services communicate with each other?
- How to manage so many services?
- How to deal with service downtime?
Spring Cloud can solve these problems!
Spring Cloud Netflix
Eureka
Eureka is a REST (Representational State Transfer) based service that provides service discovery,load balancing and failover mainly supported by AWS cloud services.We call this service Eureka service.
Eureka provides Java client components, the Eureka Client, for easy interaction with the server.Clients have built-in simple load balancing based on round-robin implementation. In Netflix, Eureka is encapsulated with a more complex load balancing scheme for high availability, which includes weighted load balancing based on traffic, resource utilization, and request return status.
All microservices need to be registered in Eureka
It solves the communication problem between micro services
Zuul
Zuul includes two main functions, routing and filtering requests:
The routing function is responsible for forwarding external requests to specific micro-service instances, which is the basis for achieving a unified entry for external access, while the filter function is responsible for intervening in the processing of requests, which is the basis for implementing such functions as request verification, service aggregation and so on. Zuul integrates with Eureka, registering Zuul as an application under Eureka Service Governance, and getting messages from other microservices from Eureka, i.e. subsequent access to microservices is acquired through a Jump from Zuul.
Zuul solves the client access problem.
Ribbon
Ribbon is an open source project published by Netflix that provides client-side software load balancing algorithms to connect NetFlix’s mid-tier services. Ribbon’s client components provide a complete set of configuration items such as connection timeouts, retries, and so on. Simply put, if you list all the machines behind LoadBalancer (LB: Load Balancer) in the configuration file, Ribbon will automatically help you connect them based on certain rules, such as simple polling, random connections, and so on. It’s also easy to use Ribbon to implement custom load balancing algorithms!
It solves service management issues.
Hystrix
Hystrix is an open source library for dealing with latency and fault tolerance in distributed systems where many dependencies inevitably fail to invoke, such as timeouts, exceptions, etc. Hystrix ensures that if a dependency fails, it will not cause overall service failures and avoid cascading failures to improve the resilience of distributed systems.
Circuit Breaker itself is a switching device that, when a service unit fails, returns a service-expected, processable alternative response (FallBack) to the caller through the failure monitoring of the breaker (similar to a fuse) instead of a long wait or throwing an exception that the calling method cannot handle, thereby ensuring that the service caller’s threads are not held up for a long time and unnecessarily. This prevents the spread of failures in distributed systems and even avalanches
The melting mechanism is a microservice link protection mechanism corresponding to avalanche effect.
When a microservice in the fan out link is unavailable or the response time is too long, the service is degraded, which breaks the call to the node’s microservice and quickly returns the wrong response information. Resume the call link when it is detected that the node’s microservice call response is normal. In the SpringCloud framework, the fusing mechanism is implemented through Hystrix. Hystrix monitors the status of calls between microservices, and when a failed call reaches a certain threshold, the default is that 20 failed calls within five seconds initiate the fuse mechanism.
It solves the problem of service downtime
Summary
Do you think JavaWeb development is broad and profound? But in fact, this was only a small part.
Nowadays, there was a better framework for the development of micro services, which was Spring Cloud Alibaba.
We need to learn more knowledge to stand firm in the tide of big data.
Author:YaoXiyuan