前言:本章将继续上一章Spring Cloud微服务,本章主要内容是API 网关,相关代码将延续上一章,如需了解请参考:Spring Cloud 微服务一:Consul注册中心

  • Spring cloud zuul概览
  • zuul 是netflix开源的一个API Gateway 服务器, 本质上是一个web servlet应用。Zuul 在云平台上提供动态路由,监控,弹性,安全等边缘服务的框架。Spring对zuul进行了整合,使开发者能够很方便地使用zuul

  • 集成zuul
    • 延续上一个项目,新建module api-gateway-zuul pom中添加zuul的依赖

        <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-starter-zuul</artifactId>
      </dependency>
    •  在启动类中添加@EnableZuulProxy注解,启用zuul
      @SpringBootApplication
      @EnableZuulProxy
      public class ApiGatewayApplication {
      public static void main(String[] args) {
      SpringApplication.run(ApiGatewayApplication.class, args);
      }
      }
    • 修改配置文件application.yml,设置相关路由,url为上一章中consul消费者的地址
      server:
      port: 8080
      spring:
      application:
      name: api-gateway-zuul
      zuul:
      routes:
      user:
      path: /user/**
      url: http://localhost:10080/
      debug: true
    • 分别启动user-service,user-consumer,api-gateway-zuul,访问 http://localhost:8080/user/users, 能够正常返回信息,说明路由已成功
    • 服务化,使用url配置路由在微服务场景下非常不方便,为此,zuul支持另外一种配置:使用serviceId
      server:
      port: 8080
      spring:
      application:
      name: api-gateway-zuul
      cloud:
      consul:
      host: localhost
      port: 8500
      discovery:
      register: false
      zuul:
      routes:
      user:
      path: /user/**
      serviceId: user-service
      debug: true

      使用serviceId替换url,值为服务提供者Id

    • 重启api-gateway-zuul,访问 http://localhost:8080/user/all, 能够正常返回信息,说明路由已成功

Spring Cloud 微服务二:API网关spring cloud zuul的更多相关文章

  1. Spring Cloud 微服务四:熔断器Spring cloud hystrix

    前言:在微服务架构中,一般都是进程间通信,有可能调用链都比较长,当有底层某服务出现问题时,比如宕机,会导致调用方的服务失败,这样就会发生一连串的反映,造成系统资源被阻塞,最终可能造成雪崩.在sprin ...

  2. 微服务&#183;API网关

    阅文时长 | 3.52分钟 字数统计 | 1232字符 主要内容 | 1.什么是API网关 2.微服务中的API网关 3.几种部署策略 『微服务·API网关』 编写人 | SCscHero 编写时间 ...

  3. .net core 微服务之Api网关(Api Gateway)

    原文:.net core 微服务之Api网关(Api Gateway) 微服务网关目录 1. 微服务引子 2.使用Nginx作为api网关 3.自创api网关(重复轮子) 3.1.构建初始化 3.2. ...

  4. SOA与ESB,微服务与API网关

    SOA与ESB,微服务与API网关 SOA: ESB: 微服务: API网关: 参考资料: 1.漫画微服务,http://www.sohu.com/a/221400925_100039689 2.SO ...

  5. 一站式入口服务|爱奇艺微服务平台 API 网关实战 原创 弹性计算团队 爱奇艺技术产品团队

    一站式入口服务|爱奇艺微服务平台 API 网关实战 原创 弹性计算团队 爱奇艺技术产品团队

  6. 【spring colud】spring cloud微服务项目搭建【spring boot2.0】

    spring cloud微服务项目搭建 =================================== 示例版本: 1.spring boot 2.0版本 2.开发工具 IntellJ IDE ...

  7. 利用 Maven 构造 Spring Cloud 微服务架构 模块使用 spring Boot构建

    采用Maven 聚合工程搭建 Spring Cloud 使用工具: IntelliJ IDEA    版本: 2019.2.2 maven             版本: 3.6.0 JDK      ...

  8. Net分布式系统之六:微服务之API网关

    本人建立了个人技术.工作经验的分享微信号,计划后续公众号同步更新分享,比在此更多具体.欢迎有兴趣的同学一起加入相互学习.基于上篇微服务架构分享,今天分享其中一个重要的基础组件“API网关”. 一.引言 ...

  9. 基于spring-cloud的微服务(4)API网关zuul

    API网关是微服务架构中的很重要的一个部分,内部有多个不同的服务提供给外部来使用,API网关可以对外做统一的入口,也可以在网关上做协议转换,权限控制和请求统计和限流等其他的工作 spring-clou ...

随机推荐

  1. Tiny6410下的第一个Linux驱动程序

    Linux系统环境是照着友善之臂的教程搭建的 //Hello  World驱动程序源文件 #include <linux/miscdevice.h> #include <linux/ ...

  2. Jackson反序列JSON为实体对象出现:no String-argument constructor/factory method to deserialize from String value的问题

    解决方法: 1.JSON字符串中有转义字符,可以替换,也可以直接toString之后清除转移字符. 参考: https://stackoverflow.com/questions/40986738/s ...

  3. 【安居客】资深PHP软件开发工程师

    工作职责: 1.网站项目的开发和维护: 2.负责技术部软件开发架构设计: 3.负责生产环境.测试环境和生产环境服务器运维和优化: 4.负责研究较前沿和复杂的技术运用: 岗位要求: 1.熟悉 PHP 程 ...

  4. espresso Seekbar

    package test.utils; import android.support.test.espresso.PerformException; import android.support.te ...

  5. ServicePointManager.ServerCertificateValidationCallback 冲突的解决

    ServicePointManager是用于创建. 维护和删除的实例的静态类ServicePoint类. 当应用程序请求对 Internet 资源统一资源标识符 (URI) 的连接通过ServiceP ...

  6. VUE -- ejs模板的书写

    1.EJS是一个简单高效的模板语言,通过数据和模板,可以生成HTML标记文本.可以说EJS是一个JavaScript库,EJS可以同时运行在客户端和服务器端,客户端安装直接引入文件即可,服务器端用np ...

  7. Chrome的Waterfall

    参考: 1.https://developers.google.com/web/tools/chrome-devtools/network-performance/reference#timing 2 ...

  8. 2017.7.1 mysql安装与启动(已验证可以使用)

    下载地址:http://learning.happymmall.com/ 之前一直用解压版安装,启动mysql服务的时候总是失败,这次用mysql installer安装一遍,终于成功启动. 1.下载 ...

  9. 2017.6.30 IDEA插件--gsonfomat的安装与使用

    参考来自:http://www.cnblogs.com/1024zy/p/6370305.html 1.安装 2.使用 (1)新建一个空类 (2)在空类里按快捷键:alt+s,打开gsonformat ...

  10. Php 中如何将内容写入log日志中

    $Str = '你想要存的内容'; file_put_contents('abc.log', "\r\n\r\n". $Str, FILE_APPEND);     FILE_AP ...