"Let you read the article again SpringCloud, miss you will regret it."


Currently the entire Spring Cloud technology components used by the company, basically contains the above figure included, have to say, Spring Cloud entire ecosystem is really powerful, easy to use and very effective.

Followed by a time for re-interpret the use of each component, the article said that the main link next Spring map Cloud architecture, the way to sort out their own ideas down for future reference.

Read catalog:

  • A gateway request process
  • Two, Eureka Service Governance
  • Three, Config configuration center
  • Four, Hystrix monitoring
  • Fifth, service call link
  • Six, ELK log link
  • Seven, unified format returns


A gateway request process


In Spring Cloud entire component library, Spring Cloud Zuul is the most easily overlooked, but also the most important, and Eureka Spring Cloud Zuul can be integrated registry, we currently use Spring Cloud Zuul the following functions:

  • Filter Filters
  • Router routing
  • Ribbon Load Balancing
  • Hystrix fuse
  • Retry Retry

Spring Cloud Zuul some features are built-in, such as Filter and Router, Spring Cloud is a combination of some other components, such as the Ribbon and Hystrix.

Here focuses on under Filter filter, the filter is divided into four types:

  • pre : Zuul executed before forwarding the request, our current implementation is AccessTokenFilter, for the authorization verification oAuth2.0 JWT.
  • route : routing execution when Zuul, the current project is useless to.
  • POST : Zuul routing execution after forwarding the request that is already successful back-end services, our current implementation is CustomResponseFilter, encapsulation format for unified request, such as code / msg / data and so on.
  • error : execution error occurs when the above filter, we now realize is CustomErrorFilter, for errors interceptor filters perform, and then return to a unified format package, in addition, error filter can not seem to catch errors occur back-end service execution .

In addition, with regard to authorization verification oAuth2.0 JWT, there are two ways to achieve:

AccessTokenFilter
复制代码

We are currently using a second way, these two methods have advantages and disadvantages, the key is their own choice, why the second approach? The purpose is to play the role of Zuul external gateway for unified authorization verification.

Authorize the Map, which stores the configuration of all the service interfaces, sample configuration:


This is our current configuration, in Spring Cloud Config configuration center, when Zuul start a static Map, behind the stores is loaded, using the Spring Cloud Bus dynamically refreshed.

About Zuul gateway, in fact, there are a lot needs to be said, followed by the opportunity for further explanation.

Two, Eureka Service Governance


AP Eureka follows the principle (service availability and fault tolerance partition), service management best to follow the principle of CAP distributed.

Eureka cluster node is the same level with each other, unlike the Consul have master / worker points, Eureka nodes in the cluster every two registered each other, so, Eureka cluster deployment best three nodes, which is our current deployment.

Call each other between the service load used in two ways:

  • Feign : based declarative, by definition, is the need to define the interface, as we usually use the same object to call.
  • Ribbon : soft load, by injecting into the RestTemplate load Handler, then load algorithm to select the call (for service registration information by Eureka).

We currently intend to use the Ribbon load way, and why? Look at the following code will know:


Three, Config configuration center


Our current distribution center using Spring Cloud Config, of course, you can also use the more powerful Polly (Ctrip open source), but Config now also able to meet our needs, our storage warehouse is now used Git.

Config Configuration Center provides data encryption, you can use the RSA encryption method, so the configuration is stored in Git is cipher text, Config Client acquisition when the encryption configuration, Config Server automatically decrypts return.

Configuration Center usage scenarios, we are mainly two places:

  • Project started configuration information, such as database connection strings and so on.
  • Business service configuration information, which is configured business-related.

In addition, should be noted that, by default, if Git configuration updates, Config Client does not update the configuration, our current solution is to use Spring Cloud Bus dynamically refresh configuration (Config Server configured), specific the process:

curl -X POST http://manager1:8180/bus/refresh
复制代码

Four, Hystrix monitoring


Hystrix mainly used service fuse / demotion / isolation process, Hystrix disposed caller, when the caller is not using the service, trigger Hystrix fuse, the method performs the specified Fallback, special handling.

I thought before the trigger condition Hystrix blown service is not available, that is, the service request timed out (such as service hung up), but I have tested, the service 500 errors, will trigger Hystrix fuse, and will automatically ignore Hystrix the timeout.

We currently use Hystrix, there are two main places:

  • Internal service calls : You can fuse handling of an API interface.
  • Zuul gateway uses : that when Zuul routing forwarding calls, but there is a limitation, is only to be blown service, and not for an API interface blown.

FIG above, the main picture is the monitoring process Hystrix, we mainly use RabbitMQ collection transmission output, turbine-server data flow polymerization, hystrix-dashboard display patterning.

Fifth, service call link


The concept of a service call link is initiated when the service request, the entire request log data link for future reference.

Currently on the market, to achieve almost all service call link, the theoretical basis of that paper are based on Google Dapper, the most important concept is traceId and spanId.

  • traceId record ID entire service link created by the first requester, the only link service.
  • spanId record the current block ID service, created by the current services side.
  • ParentId recorded on a spanId service request.

I described below under our current service call link process:

  • H5 initiate the request, the gateway to Zuul, Zuul create global traceId and their spanId, then carry the data to the business service A, and use Spring Cloud Sluth transferred to RabbitMQ.
  • Business Service A, and spanId Zuul traceId received transmission, then the parentId Zuul is provided spanId, and generate their own spanId, and bring the data to the business services B, and transmitted to the utilizing Spring Cloud Sluth RabbitMQ.
  • ....

The above figures, the detailed description of the whole process service call link, under the technology stack used to say here:

  • Spring Cloud Sluth: and the probe is relatively similar concepts SkyWalking, each service is configured, of course, to collect the requested data service (traceid and spanId), and then using a stream-sluth binder-rabbit assembly, the data transmission request to RabbitMQ.
  • Spring Cloud Zipkin: UI display for requesting the main link, Zipkin RabbitMQ data read requests from, and then stored in the ElasticSearch then read directly from the next display in ElasticSearch.
  • Kibana: Kibana request data can also be displayed in ElasticSearch, but not graphic, you need to create the index configuration.

Six, ELK log link


The above figure is very detail the process under the ELK, ELK technical default of the stack is not Filebeat, when Logstash used as a log collection, CPU and memory resources will take up relatively large, so we use a log of lightweight Filebeat collection, Filebeat deployment server located in each business service, and then transfer the collected log data to Logstash, Logstash can be deployed on two or three servers, as filters and analysis of logs, logs and then treatment data transmitted to the storage ElasticSearch.

Seven, unified format returns

This is my own work progress SpringCloud, I want to help to grow together in


Reproduced in: https: //juejin.im/post/5d00e1e06fb9a07ee0631036

Guess you like

Origin blog.csdn.net/weixin_34249367/article/details/93180615