In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "how to achieve client-side load balancing in SpringCloud". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to achieve client-side load balancing in SpringCloud".
What is Spring Cloud
Spring Cloud is a micro-service framework. Compared with RPC frameworks such as Dubbo, Spring Cloud provides a full range of distributed system solutions.
Spring Cloud encapsulates several open source components of the micro services infrastructure Netflix and integrates with the cloud platform and the Spring Boot development framework.
Spring Cloud provides a simple development method for configuration management, service governance, circuit breaker mechanism, intelligent routing, micro-agent, control bus, one-time token, global consistency lock, leader election, distributed session, cluster state management and other operations involved in the development of micro-service architecture. Spring Cloud provides developers with tools to quickly build distributed systems, developers can quickly start services or build applications, and can quickly interface with cloud platform resources.
II. SpringCloud architecture
Spring Cloud is an ordered collection of frameworks. It makes use of the development convenience of Spring Boot to skillfully simplify the development of distributed system infrastructure, such as service discovery registration, configuration center, message bus, load balancing, circuit breaker, data monitoring and so on. It can be started and deployed with one button with the development style of Spring Boot. Spring does not repeat manufacturing wheels, it just combines the more mature service frameworks developed by various companies that can stand the actual test, and shields the complex configuration and implementation principles through Spring Boot style re-encapsulation, and finally leaves a set of distributed system development kits that are easy to understand, easy to deploy and easy to maintain. Spring Cloud is to further encapsulate a number of open source components of Netflix, and at the same time achieve a good integration with the cloud platform and Spring Boot development framework. Spring Cloud is a relatively new micro-service framework, with release version 1.0 only launched in 2016. Although Spring Cloud time is the shortest, compared with RPC frameworks such as Dubbo, Spring Cloud provides a full range of distributed system solutions. Spring Cloud provides developers with tools to quickly build in distributed systems (configuration management, service discovery, circuit breakers, routing, micro-agents, control bus, disposable token, full residence, leader election, distributed session, cluster status). Developers using Spring Cloud can quickly start services or build applications and quickly interface with cloud platform resources.
III. Composition of Spring Cloud
The subprojects of Spring Cloud can be roughly divided into two categories, one is the encapsulation and abstraction of the existing mature framework "Spring Boot", but also the largest number of projects; the second is the development of a part of the distributed system infrastructure implementation, such as Spring Cloud Stream plays the role of kafka, ActiveMQ. For developers who want to implement micro-services quickly, the first type of subprojects is enough, such as Spring Cloud Netflix, which encapsulates a distributed service framework developed by Netflix, including service discovery and registration, load balancing, circuit breakers, REST clients, request routing, and so on. This project is one of the sub-projects of Spring Cloud, the main content is the packaging of a series of open source products of Netflix, it provides self-configured Netflix OSS integration for Spring Boot applications. With some simple annotations, developers can quickly configure common modules in applications and build huge distributed systems. Its main modules include: service Discovery (Eureka), Circuit Breaker (Hystrix), Intelligent routing (Zuul), client load balancing (Ribbon) and so on.
Spring Cloud Netflix this is a big boss, second only to the boss, who relies on it for all kinds of services and integrates with various Netflix OSS components to form the core of micro services. Its younger brothers mainly have Eureka, Hystrix, Zuul and Archaius.... Too much
(1). Spring Cloud Eureka service discovery
1 、 netflix-eureka
2. Spring Cloud Eureka service discovery
3 、 Eureka
Service Center, Cloud Service Discovery, a REST-based service for locating services to enable cloud middle-tier service discovery and failover. This is the most awesome younger brother of SpringCloud, the service center. Any younger brother who needs the support of other younger brothers needs to take anything from here. Similarly, if you have any unique martial arts, you will hurry to report it, so it is convenient for other boys to call it later. The advantage of it is that you don't need to find all kinds of little brothers directly for support, you just need to go to the service center to get it, and you don't need to know where the other boys who provide support are, or a few boys to support them. Anyway, you can just use it. The service center ensures stability and quality. Spring Cloud Eureka provides the functions of service discovery and service registration in a distributed environment. A RESTful service that locates middle-tier services running in the AWS region (Region). It consists of two components: the Eureka server and the Eureka client. The Eureka server is used as the service registration server. The Eureka client is a java client that simplifies interaction with the server, acts as a polling load balancer, and provides failover support for services. Netflix uses a different client in its production environment, which provides weighted load balancing based on traffic, resource utilization, and error status.
(2) Spring Cloud Ribbon client load balancing
1 、 netflix-ribbon
2 、 Spring Cloud Ribbon
Ribbon, which mainly provides software load balancing algorithm on the client side. The Ribbon client component provides a complete set of configuration options, such as connection timeout, retry, retry algorithm, and so on. Ribbon has built-in pluggable and customizable load balancing components. Here are some load balancing strategies used:
Simple polling load balancing weighted response time load balancing region-aware polling load balancing random load balancing
The following features are also included in Ribbon:
Easy to integrate with service discovery components (such as Netflix's Eureka) using Archaius to complete runtime configuration using JMX to expose operation and maintenance metrics, using Servo to publish multiple pluggable serialization options asynchronous and batch operations (coming soon) automatic SLA framework (coming soon) system management / metrics console (coming soon)
(3) Spring Cloud Config
1 、 spring-cloud-config
Commonly known as the configuration center, the configuration management toolkit allows you to put the configuration on a remote server and centrally manage the cluster configuration, which currently supports local storage, Git, and Subversion. That is, in the future, everyone's weapons, gunfire and other things will be put together, and do not bring them casually, so as to facilitate unified management and upgrading of equipment in the future.
2. Spring Cloud Config configuration Center
The configuration information is centrally saved, and the configuration Spring Cloud Bus can be used to modify the configuration file dynamically. This is still static and needs to be updated dynamically with Spring Cloud Bus.
3 、 Spring Cloud Config
Spring Cloud Config is our usual configuration center. Spring Cloud Config- extracts the configuration that the application originally placed in the local file and puts it on the central server, which is essentially the migration of configuration information from the local to the cloud. Thus, it can provide better management and publishing ability. The Spring Cloud Config is divided into the server and the client. The server is responsible for publishing the configuration files stored in git (svn) into the REST interface, and the client can obtain the configuration from the server REST interface. However, the client cannot actively perceive the change in the configuration and take the initiative to obtain the new configuration, which requires each client to trigger its own / refresh through the POST method.
(4) Spring cloud Hystrix fuse
1 、 netflix-hystrix
Fuses, fault-tolerant management tools, are designed to control the nodes of services and third-party libraries through fuse mechanisms, thus providing stronger fault tolerance for delays and failures. For example, suddenly a little brother gets sick, but you still need its support, and then it doesn't respond for a long time after calling it, but you don't know, you've been waiting for this response; it's possible that other boys are also calling your kung fu stunts, so when there are too many requests, there will be serious blocking that will affect the boss's overall plan. At this time, Hystrix will come in handy. When Hystrix finds that some younger brother is not in a stable state, immediately let it off the line, let other boys come up, or tell you that you don't have to wait for this little brother today.
2. Spring cloud Hystrix fuse
A circuit breaker (Cricuit Breaker) is a facility that automatically fuses (turns on the switch) when the remote service is unavailable and automatically recovers (closes the switch) when the remote service is restored. Spring Cloud provides circuit breaker, resource isolation and self-repair functions through the Hystrix component of Netflix.
A circuit breaker prevents an application from repeatedly trying to perform an operation that is likely to fail, allowing it to continue without waiting for fault recovery or wasting CPU cycles, and it determines that the fault is persistent. Circuit breaker mode also enables the application to detect whether the fault has been resolved. If the problem seems to have been corrected, the application can try to invoke the operation.
3 、 Hystrix01
Circuit breakers add stability and flexibility to a system that provides stability while the system recovers from a fault and minimizes the impact of this fault on performance. It helps to quickly reject an operation that is likely to fail, rather than waiting for a request that the operation times out (or does not return) to maintain the response time of the system. If the circuit breaker increases the time each time the state is changed, this information can be used to monitor the health of the components of the system protected by the circuit breaker, or to remind the administrator when the circuit breaker is tripped to be in the open state.
4 、 Hystrix02
5. Hystrix flow chart
(5) Spring Cloud Zuul service gateway, intelligent routing
1 、 netflix-zuul
Zuul is a framework that provides dynamic routing, monitoring, resiliency, security and other edge services on cloud platforms. Zuul acts as the front door for all requests at the back end of the Web website for devices and Netflix streaming applications. When other doors send to see the eldest brother to do business, you must first go through the zuul to see if you have brought a knife or something to intercept it back, or if you need to find that little brother to take it directly to you.
2. Spring Cloud Zuul Service Gateway
3 、 Zuul
Similar to Nginx, reverse proxy function, but netflix itself adds some features to work with other components.
(VI), Spring Netflix Archaius
1 、 netflix-archaius
Configuration management API, including a series of configuration management API, provides dynamic typed properties, thread-safe configuration operations, polling framework, callback mechanism and other functions. You can obtain the configuration dynamically by reading the content from the configuration source every 60s (default, configurable), so that you can make the modified content take effect without restarting the service after modifying the configuration file, as long as you use the API of archaius to read it.
(7), Spring Cloud Bus
1 、 spring-cloud-bus
Events, message buses, which are used to propagate state changes in a cluster (for example, configuration change events), can be hot deployed in conjunction with Spring Cloud Config. Equivalent to the Water margin, which travels 800 miles from Japan to Japan, Shenxing Taibao Daizong ensures that the news between each younger brother remains smooth.
Distributed message queuing is the encapsulation of Kafka and MQ; events and message buses are used to propagate state changes in clusters (for example, configuration change events) and can be deployed in conjunction with Spring Cloud Config. Spring cloud bus connects distributed nodes through a lightweight message broker. This can be used for broadcast state changes (such as configuration changes) or other message instructions. One of the core ideas of Spring bus is to extend spring boot applications through distributed initiators, and it can also be used to establish a communication channel between multiple applications. Currently, the only way to do this is to use the AMQP message broker as the channel, and the same feature settings (some depending on the channel settings) are in more channel documentation. Spring cloud bus is translated as a message bus by many people in China, which is also quite vivid. We can understand it as managing and spreading messages in all distributed projects. In fact, the essence is to use the broadcast mechanism of MQ to spread messages in distributed systems. At present, the commonly used ones are Kafka and RabbitMQ. Many things can be done by using the mechanism of bus, among which the configuration center client refresh is one of the typical application scenarios. We use a diagram to describe the mechanism used by bus in the configuration center.
2 、 Spring Cloud Bus
According to this figure, we can see the steps of using Spring Cloud Bus to make configuration updates:
The submission code triggers post to send client A to send bus/refresh client A to receive a request to update the configuration from the server and send it to Spring Cloud BusSpring Cloud bus to receive a message and notify other clients to receive a notification, requesting the server to get the latest configuration. All clients get the latest configuration.
(8), Spring Cloud Security
1 、 spring-cloud-security
Encapsulation of Spring Security, and can be used with Netflix, security toolkit, add security control for your application, mainly refers to OAuth3. Spring security-based security toolkit to add security controls to your application. This little brother is very good-nosed and specializes in the security of the whole gang. He sets up different factions to visit specific resources, so he can't reveal the secret book of Sunflower.
(IX), Spring Cloud Zookeeper
1 、 spring-cloud-zookeeper
The encapsulation of Zookeeper to configure the use of other Spring Cloud subprojects; a toolkit for operating Zookeeper for service registration and discovery using zookeeper. ZooKeeper is a distributed, open source distributed application coordination service, an open source implementation of Google's Chubby, and an important component of Hadoop and Hbase. It is a software that provides consistency services for distributed applications, including configuration maintenance, domain name services, distributed synchronization, group services and so on. The goal of ZooKeeper is to encapsulate complex and error-prone key services and provide users with simple and easy-to-use interfaces and systems with efficient performance and stable functions. A toolkit for operating Zookeeper for service discovery and configuration management using zookeeper, holding Zookeeper's thighs.
(X), Spring Cloud Stream
Spring-cloud-stream
Data flow; data flow operation development kit, which encapsulates sending and receiving messages with Redis,Rabbit, Kafka, etc. Spring Cloud Stream is a framework for creating message-driven microservice applications. Spring Cloud Stream is based on spring boot to build stand-alone / industrial-level spring applications, using spring integration to provide connectivity to message agents. Data flow operation development kit, which encapsulates sending and receiving messages with Redis,Rabbit, Kafka, etc. A business involves multiple tasks, and tasks are triggered by events, which is what Spring Cloud stream does.
(11), Spring Cloud Sleuth
Spring-cloud-sleuth
Service tracking; log collection toolkit that encapsulates Dapper,Zipkin and HTrace operations. Log collection toolkit, which encapsulates Dapper and log-based tracking as well as Zipkin and HTrace operations, implements a distributed tracking solution for SpringCloud applications.
(12) Spring Cloud Feign uses HTTP to request remote services
Netflix-feign
In the Spring Cloud Netflix stack, each micro-service exposes its own services in the form of a HTTP interface, so the HTTP client must be used when invoking remote services. We can use JDK's native URLConnection, Apache's Http Client, Netty's asynchronous HTTP Client, and Spring's RestTemplate. However, the most convenient and elegant to use is Feign. Feign is a declarative, templated HTTP client. Using Feign in Spring Cloud, we can achieve the same coding experience when using HTTP to request a remote service as when calling a local method, and developers are completely unaware that this is a remote method, let alone a HTTP request. With Feign, we can make HTTP remote calls completely transparent to developers and get a coding experience consistent with calling local methods. This is similar to the way remote services are exposed in Ali Dubbo, except that Dubbo is based on a private binary protocol, while Feign is essentially a HTTP client. If you are using Spring Cloud Netflix to build micro services, then Feign is the best choice.
(XIII) Spring Cloud for Cloud Foundry
Pivotal-cloud-foundry
CloudFoundry is the industry's first open source PaaS cloud platform launched by VMware. It supports a variety of frameworks, languages, runtime environments, cloud platforms and application services, enabling developers to deploy and expand applications in a few seconds without having to worry about any infrastructure problems. It is actually a set of solutions integrated with CloudFoundry, hugging CloudFoundry's thighs.
(14), Spring Cloud Cluster
Spring-cloud-cluster
Spring Cloud Cluster will replace Spring Integration. Provide basic functional support for clusters in distributed systems, such as election, state consistency of clusters, global locking, tokens and other common state patterns of abstraction and implementation. If you organize different gangs into a unified whole, Spring Cloud Cluster has provided you with a lot of tools to facilitate organizing into a unified group.
(15), Spring Cloud Consul
Hashicorp-consul
Consul is a service software that supports multi-data center distributed and highly available service discovery and configuration sharing. It is developed by HashiCorp in Go language and is open source based on Mozilla Public License 2.0 protocol. Consul supports health check and allows HTTP and DNS protocols to call API to store key-value pairs. Spring Cloud Consul encapsulates Consul operations, and consul is a service discovery and configuration tool that integrates seamlessly with Docker containers.
(16), Spring Cloud Data Flow
Spring-cloud-data-flow
Data flow is a unified programming model and managed service for developing and performing a wide range of data processing patterns including ETL, batch and continuous computing. For micro-service programs that can be composed in a modern operating environment, Spring Cloud data flow is a service that can be provisioned by a native cloud. With Spring Cloud data flow, developers can create and configure data channels (data pipelines) for common use cases such as data extraction, real-time analysis, and data import / export. Spring Cloud data flow is a redesign of spring XD based on native cloud. The goal of the project is to simplify the development of big data's application. The refactoring of Spring XD stream processing and batch processing module is based on spring boot's stream and task/batch micro-service programs respectively. These programs are now automated deployment units and their native support for modern operating environments such as Cloud Foundry, Apache YARN, Apache Mesos, and Kubernetes. Spring Cloud data flow provides a series of models and best practices for distributed streaming and batch data channels based on microservices.
(17), Spring Cloud Task
Spring-cloud-task
Spring Cloud Task mainly deals with task management and task scheduling of short-lived micro-services, such as some scheduled tasks running once at night, or some data analysis running several times temporarily.
(18), Spring Cloud Connectors
Spring-cloud-connectors
Spring Cloud Connectors simplifies the process of connecting to services and obtaining operations from the cloud platform. It is highly scalable and you can use Spring Cloud Connectors to build your own cloud platform. It is convenient for cloud applications to connect to the back end on various PaaS platforms, such as database and message broker services.
(19), Spring Cloud Starters
Spring-cloud-starters
Spring Boot-style startup project that provides out-of-the-box dependency management for Spring Cloud.
(20), Spring Cloud CLI
Spring-cloud-cli
Based on Spring Boot CLI, it allows you to quickly build cloud components on the command line.
(21), Netflix Turbine
Netflix-turbine
Turbine is a tool for the aggregation server to send event flow data, which is used to monitor the metrics of hystrix under the cluster.
What is the relationship with Spring Boot
Spring boot is a set of rapid configuration scaffolding of Spring, which can quickly develop individual micro services based on spring boot, Spring Cloud is a cloud application development tool based on Spring Boot, Spring boot focuses on individual individuals with fast and easy integration, and Spring Cloud is a global service governance framework. Spring boot uses the concept that the default is larger than the configuration. Many integration solutions have been selected for you. If you don't configure it, you don't have to configure it. A large part of Spring Cloud is based on Spring boot, so can it not be based on Spring boot? No. Spring boot can use the development project independently without Spring Cloud, but Spring Cloud can not be separated from Spring boot and belongs to the dependency relationship.
A relationship like Spring-> Spring Boot > Spring Cloud.
Thank you for your reading. the above is the content of "how to achieve client-side load balancing in SpringCloud". After the study of this article, I believe you have a deeper understanding of how to achieve client-side load balancing in SpringCloud, and the specific usage needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.