SpringCloudAlibaba 개발 환경의 퓨즈 Sentinel 구축

SpringCloudAlibaba 개발 환경의 퓨즈 Sentinel 구축
  • 구축 공급 자 와 소비자
  • 소비자 에 게 퓨즈 구축
  • 프로젝트 개발 자가 sentinel dashboard 모니터링 을 통 해 녹 아내 림
  • sentinel 대시 보드 환경 구축 (Windows)
  • springcloudaliaba 와 sentinel 버 전 의존 관계 명 확 히
  • sentinel 대시 보드 다운로드
  • sentinel 대시 보드 시작
  • sentinel 대시 보드 방문

  • 소비자 에 게 sentinel dashboard
  • 를 통합 한다.
    구축 공급 자 와 소비자
    SpringCloudAlibaba 개발 환경 을 구축 하 는 서비스 소비자 와 공급 자 는 feign 을 통 해 통신 합 니 다.
    소비자 들 사이 에 퓨즈 를 세우다
    우리 프로그램의 서비스 제공 자가 고장 이 났 을 때 소비자 중의 퓨즈 는 이번 프로그램의 대상 이 요청 한 응답 을 제때에 끝내 고 servlet 용기 의 스 레 드 를 방출 하여 servlet 스 레 드 가 소모 되 지 않도록 합 니 다. 즉, 전체 마이크로 서비스 가 마비 되 는 것 입 니 다. 즉, 눈사태 가 발생 하 는 것 입 니 다.
    sentinel 의존 가입
    
        4.0.0
        bygones-consumer
        1.0.0-SNAPSHOT
        jar
    
        
            com.bygones
            bygones-dependencies
            1.0.0-SNAPSHOST
            ../bygones-dependencies/pom.xml
        
    
        
            
                org.springframework.boot
                spring-boot-starter-web
            
    
            
                org.springframework.boot
                spring-boot-starter-actuator
            
    
            
            
                com.alibaba.cloud
                spring-cloud-starter-alibaba-nacos-discovery
            
    
            
            
                org.springframework.cloud
                spring-cloud-starter-openfeign
            
    
            
            
                com.alibaba.cloud
                spring-cloud-starter-alibaba-sentinel
            
        
    
    
    

    application. yml 에서 sentinel 서 비 스 를 엽 니 다.
    spring:
      application:
        name: consumer
      cloud:
        nacos:
          discovery:
            server-addr: 127.0.0.1:8848
    server:
      port: 8081
    feign:
      sentinel:
        enabled: true #      sentinel
    

    녹 아내 릴 때 실행 하 는 방법 만 들 기
    import com.bygones.consumer.service.AccessProviderService;
    import org.springframework.stereotype.Service;
    
    /**
     *   
     *                 
     * feign                 ,    servlet         
     */
    @Service
    public class AccessProviderServiceFallback implements AccessProviderService {
         
    
        @Override
        public String consumerAccessProvider(String message) {
         
            return "            ";
        }
    }
    

    feign 인터페이스 에서 녹 아내 릴 때 실행 되 는 함 수 를 호출 합 니 다.
    import com.bygones.consumer.service.impl.AccessProviderServiceFallback;
    import org.springframework.cloud.openfeign.FeignClient;
    import org.springframework.web.bind.annotation.GetMapping;
    import org.springframework.web.bind.annotation.PathVariable;
    
    /**
     * feign  
     * (1)   FeignClient        
     * (2)          mapping            
     */
    @FeignClient(value = "provider", fallback = AccessProviderServiceFallback.class) // value        application.name, fallback         
    public interface AccessProviderService {
         
        @GetMapping("consumer-access-provider/{message}") //   mapping           ,      mapping    
        String consumerAccessProvider(@PathVariable("message") String message); //                       
    }
    

    프로젝트 개발 자 는 sentinel dashboard 모니터링 을 통 해 녹 습 니 다.
    위의 설정 을 통 해
    sentinel 대시 보드 환경 구축 (Windows)
    springcloudaliaba 와 sentinel 버 전 의존 관 계 를 명 확 히 합 니 다.
    https://github.com/alibaba/spring-cloud-alibaba/wiki/버 전 설명
    sentinel 대시 보드 다운로드
    sentinel 대시 보드 다운로드
    sentinel 대시 보드 다운로드 주소https://github.com/alibaba/Sentinel/releases/tag/1.7.1
    sentinel 대시 보드 시작
    sentinel dashboard 는 표준 Springboot 프로젝트 입 니 다.
    시작 명령
    java -Dserver.port=8090 -Dcsp.sentinel.dashboard.server=localhost:8090 -Dproject.name=sentinel-dashboard -jar sentinel-dashboard-1.7.1.jar
    

    sentinel 대시 보드 방문
    http://localhost:8090/ 포트 는 시작 입 니 다. 설정 한 포트 사용자 이름 / 비밀번호 sentinel / sentinel 입 니 다.
    소비자 통합 sentinel dashboard
    프로필 application. yml 에서 소비 자 를 sentinel dashboard 에 등록 합 니 다 spring. cloud. sentinel. transport. dashboard
    spring:
      application:
        name: consumer
      cloud:
        nacos:
          discovery:
            server-addr: 127.0.0.1:8848
        sentinel:
          transport:
            dashboard: localhost:8090 #       sentinel dashboard 
    server:
      port: 8081
    feign:
      sentinel:
        enabled: true #      sentinel
    

    좋은 웹페이지 즐겨찾기