zoukankan      html  css  js  c++  java
  • 007API网关服务Zuul

    001、POM配置

      和普通Spring Boot工程相比,增加了Eureka Client、Zuul依赖和Spring Cloud依赖管理

    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-eureka</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-zuul</artifactId>
        </dependency>
    </dependencies>
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring-cloud.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    002、使能Zuul Proxy

    @SpringBootApplication
    @EnableZuulProxy    //使能API网关
    public class APIGatewayZuulApplication {
    
        public static void main(String[] args) {
            SpringApplication.run(APIGatewayZuulApplication.class, args);
        }
    }

    003、src/main/resources下配置文件application.yml

    spring:
      application:
        name: api-gateway-zuul
    server:
      port: 5001
    eureka:
      client:
        serviceUrl:
          defaultZone: http://discovery:1000/eureka/

    使用步骤:

      a)启动Eureka Server服务eureka-server

      b)启动Hello Service服务hello-service-provider(可启动多个)

      c)启动api-gateway-zuul服务

      d)通过http://localhost:5001/hello-service-provider/hello即可访问Hello Service的服务

    004、自定义服务路径

    zuul:
      routes:
        sayhello:                               # 可以随便写,在zuul上面唯一即可;当这里的值 = service-id时,service-id可以不写。
          path: /sayhello/**                    # 想要映射到的路径
          service-id: hello-service-provider    # Eureka中的serviceId

      此时通过http://localhost:5001/sayhello/hello即可访问Hello Service的服务

    005、忽略指定服务不代理

    zuul:
      ignored-services: hello-service-provider

      此时hello-service-provider服务不会被代理

  • 相关阅读:
    "alert(1) to win" writeup
    "CoolShell puzzle game" writeup
    Maximum Subarray(最大连续子序列和)
    hacking 学习站
    爬虫:备份人人网状态
    ichunqiu在线挑战--网站综合渗透实验 writeup
    ichunqiu在线挑战--我很简单,请不要欺负我 writeup
    IDF-CTF-简单的js加密 writeup
    IDF-CTF-cookie欺骗 writeup
    IDF-CTF-不难不易的js加密 writeup
  • 原文地址:https://www.cnblogs.com/geniushuangxiao/p/7219528.html
Copyright © 2011-2022 走看看