Spring Cloud for Alibaba's Sentinel Integration (4)

A, Sentinel-related  

 What is Sentinel

  With the stability between the popular micro-services, services, and services is becoming increasingly important.

      Sentinel is a distributed service-oriented architecture lightweight flow control products, resource dimension to flow as the starting point, the flow control, fuse downgrade, the system load in the dimension of protection to help you protect the stability of the service.

  Sentinel contrast with Hystrix

     A detailed comparison, can be seen here ( compare with Hystrix the Sentinel ) https://yq.aliyun.com/articles/623424  ,

    To sum it up: Sentinel lighter, stronger performance, application scenarios, the framework for more and more flexible!

 Source and principle of interpretation Sentinel

     You can look at Jane book (Abelia) articlehttps://www.jianshu.com/nb/34444279 

     Understand the concepts of Sentinel, node, call chain, demotion and other source code, most of it is quite easy to understand. Sliding window with a warm-up function of the code, I am ashamed, a little not quite understand.

   

Two, Sentinel console launch

 Let's start in the original project code above, Sentinel access control function.

  1. Download Sentinel dashboard console.

     Directly on the GitHub Sentinel open source project release page  https://github.com/alibaba/Sentinel/releases , download jar package sentinel-dashboard-1.6.3.jar 

    Once downloaded, the jar into the directory page, enter the console: java -Dserver.port = 7070 -Dcsp.sentinel.dashboard.server = localhost: 7070 -Dproject.name = sentinel-dashboard -jar sentinel-dashboard-1.6.3. jar start

  dashboard project, in fact, embedded in the Sentinel client components periodically send heartbeat information like console, in addition to information on the web configuration console port, as well as the Console  

Parameter Description: 
server.port = 7070   ##-port console web 
csp.sentinel.dashboard.server = localhost: 7070   ## console access url 
project.name = ## Sentinel-Dashboard console project name

   2. After starting page

     After starting in the browser input:  http://127.0.0.1:7070  , the default user name and password: sentinel / sentinel can enter the page, shown below:

                       

   You can click on the relevant menu on the left, view the pages experience.

Third, the project Sentinel components access

   1. Simple access to Sentinel

      Simple access to the Sentinel, to Dubbo, for example, needs to be introduced sentinel-core, sentinel-apache-dubbo-adapter (comprising the core package), sentinel-transport-simple-http,

     The actual introduction of the package as follows:

    <!-- sentinel.version = 1.6.3 -->
      <dependency>
            <groupId>com.alibaba.csp</groupId>
            <artifactId>sentinel-transport-simple-http</artifactId>
            <version>${sentinel.version}</version>
        </dependency>

        <dependency>
            <groupId>com.alibaba.csp</groupId>
            <artifactId>sentinel-apache-dubbo-adapter</artifactId>
            <version>${sentinel.version}</version>
        </dependency>
sentinel-transport-simple-http package is a client sends a heartbeat to the dashboard, the project traffic statistics 
sentinel-apache-dubbo-adapter package is adapted to dubbo of, provider-side main code: SentinelDubboProviderFilter, providing end filter in service, of the inlet flow control

2. sentinel configuration

  sentinel startup, you need to configure some basic information:

       1. project.name: Project Name

      2. csp.sentinel.api.port: a local port for receiving a request dashboard,

      3. csp.sentinel.dashboard.server: console dashboard, used to send heartbeat, statistical information on the console

   Configuration:

        1 can be specified by parameters when starting the JVM -D in which IDE can configure

        2. main startup, set by System.setProperty. 1 equivalent effect, relatively easy to copy and paste.

       3. In addition to  project.name well logs configuration items (e.g.  csp.sentinel.log.dir), the remaining parameters may be specified by the properties file, path ${user_home}/logs/csp/${project.name}.properties

       4. Access alicloud-sentinel-starter assembly, can be arranged in a configuration file, (the actual effect is arranged to read, to step 2, the subsequent talk) 

    1 configurations are too complex and not conducive to IDE inside the batch can be started, the first three kinds, configured in several places, change inconvenient. I am currently in debugging inside the IDE, start the application, the use of two kinds.

   code show as below:

@EnableDiscoveryClient 
@SpringBootApplication 
public class ProductDemoApplication { 

    static { 
        initSentinelProperty (); 
    } 
    Private static void initSentinelProperty () {// Start configuration settings 
        when // start error; System.setProperty ( "java.net.preferIPv4Stack", " true") , the official recommendation of only ip ipv4 
        ( "project.name", "Product-Demo") System.setProperty; 
        System.setProperty ( "csp.sentinel.api.port", "7081"); 
        System.setProperty ( "csp .sentinel.api.port "," 127.0.0.1:7070 "); 
    } 
    public static void main (String [] args) { 
        SpringApplication.run (ProductDemoApplication.class, args); 
    } 
} 

After configuration, start the application. After starting, be sure to access the application, call the relevant resources , or the heartbeat does not start sentinel logic, dashboard does not display.

 

3. dashboard for limiting exemplary binding

  1. Start product-demo, order-demo, access order-demo, low-level calls product-demo of the service, after calling several times, will again see a dashboard-related data.

 

  

 After accessing resources in the Sentinel console, there have been related resources, real-time monitoring data.

  2. resource / test / testProductByName / ha provided limiting, QPS 2, another rejected the request several times, the browser displays:   Blocked by the Sentinel (Flow Limiting)

Rule settings:

             

 

 Sentinel displayed inside the graph below:

 

 4. Summary

   Sentinel basically very simple to use, AliCloud to do a lot of adaptation framework, a simple introduction to the appropriate adapter. Specific use, reference may sentinel of wikii : HTTPS: //github.com/alibaba/Sentinel/wiki/%E4%B8%BB%E9%A1%B5 

    However, in production use, but also the need for appropriate additional configuration and transformation, this follow-up study.

Guess you like

Origin www.cnblogs.com/keep-code/p/11381618.html