前言:本章将继续上一章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. C#实现简单的字符串加密

    最近用到一些字符串加密,而.net中提供的加密算法中用起来比较复杂,便简单的封装了一下,方便日后使用.     public class Encrypt    {        static Enco ...

  2. 使用 SVG 来实现波浪 (wave) 动画效果

    如下图所示的波浪动画效果,实现方法有很多,比如CSS或者是js等方法都可以实现.不过,要是使用SVG来实现的,我觉得比其它两种方法都要简单.这篇文章就来讲讲使用SVG来实现类似这样的波浪动画效果是多么 ...

  3. How does a single thread handle asynchronous code in JavaScript?

    原文:https://www.quora.com/How-does-a-single-thread-handle-asynchronous-code-in-JavaScript ----------- ...

  4. [Algorithms] Divide and Recurse Over an Array with Merge Sort in JavaScript

    Merge sort is a recursive sorting algorithm. If you don't understand recursion, I recommend finding ...

  5. Weblogic OutOfMemory exception的误解 -- thread limitation

    不是全部的OutofMemory exception都是内存问题... 前几天有个客户的site报了下面错误: [ERROR][thread ] Could not start thread Time ...

  6. 服务器和java程序的桥梁--jdbc/hibernate

    现实的应用程序都是用户通过可视化界面发出指令从而修改数据库.本篇文章以Oracle为例,模拟怎么通过java代码实现数据库的增删改查. 新建一个Java项目,要建好桥梁,首先要拷入驱动Jar包放在项目 ...

  7. Architects Must Be Hands On

     Architects Must Be Hands On John Davies A good ARCHiTECT SHould lEAd By ExAMplE. He (or she) shoul ...

  8. react-native 初始化 各种报错 及 解决方案

    1.Unable to load script from assets 'index.android.bundle'. curl -k "http://localhost:8081/inde ...

  9. python第一个web程序

    例一: import web urls= ('/(.*)','index') app= web.application(urls,globals()) class index: def GET(sel ...

  10. ACM-百度之星资格赛之Labyrinth——hdu4826

    Labyrinth Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...