SpringCloud Zuul 의 사용 안내

2931 단어 SpringCloudZuul
간단 한 소개
  • Zuul 은 Spring Cloud 온 가족 통 의 마이크로 서비스 API 게 이 트 웨 이 이다.장치 나 사이트 에서 오 는 모든 요청 은 Zuul 을 거 쳐 백 엔 드 에 도착 하 는 넷 플 릭 스 응용 프로그램 입 니 다
  • Zuul 은 주로 경로(전송 요청)와 여과 을 제공 합 니 다
  • 주 얼 은 결국 유레카 에 주입 된다.
    제공:에이전트,필터,루트 3 대 기능
    쓰다
    가 져 오기 의존
    
        <!--zuul  、zuul     eureka -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-zuul</artifactId>
            <version>1.4.6.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
            <version>2.0.2.RELEASE</version>
        </dependency>
    
    프로필
    
    server:
      port: 9527
    spring:
      application:
        name: springcloud-zuul
    eureka:
      client:
        service-url:
          defaultZone: http://eureka1:7001/eureka/,http://eureka2:7002/eureka/,http://eureka3:7003/eureka/
    
      instance:
        instance-id: zull9527.com #  
    
    
    오픈 지원
    
    @SpringBootApplication
    @EnableZuulProxy//  zuul  ,     Eureka
    public class Zuul9527Application {
        public static void main(String[] args) {
            SpringApplication.run(Zuul9527Application.class,args);
        }
    }
    
    이 때 우 리 는 주소:포트 번호/서비스 이름/서 비 스 를 통 해 접근 할 수 있 습 니 다.
    메모:host 파일 에 127.0.01 ww,zuultest.com 을 추가 해 야 합 니 다.

    Google 서비스 이름 이 노출 되 지 않도록 설정 파일 에 추가 할 수 있 습 니 다.
    
    zuul:
      routes:
        xxx.serviceId: provider-name # xxx      
        xxx.path: /mydept/** 
      ignored-services: provider-name #                        
      prefix: /lin #           /lin
    
    이 때 는 주소:포트 번호/lin/my dept/서비스 로 만 접근 할 수 있 습 니 다.

    추가:왜 설정 파일 에 serviceId 와 path 를 사용 하 는 지 zull 에서 route 는 키 쌍 으로 저 장 됩 니 다.
    
    public void setRoutes(Map<String, ZuulRoute> routes) {
    		this.routes = routes;
    	}
    
    Zuul Properties 에서
    
    /**
     * Represents a Zuul route.
     */
    public static class ZuulRoute {
            /**
             * The path (pattern) for the route, e.g. /foo/**.
             */
            private String path;
            /**
    	* The service ID (if any) to map to this route. You can specify a physical URL or
            * a service, but not both.
    	*/
             private String serviceId;
          }
    
    이상 은 SpringCloud Zuul 의 사용 프로필 에 대한 상세 한 내용 입 니 다.SpringCloud Zuul 의 사용 에 관 한 자 료 는 저희 의 다른 관련 글 을 주목 해 주 십시오!

    좋은 웹페이지 즐겨찾기