zoukankan      html  css  js  c++  java
  • zuul入门案例

    zuul入门案例

    1、简介

    在分布式系统系统中,有商品、订单、用户、广告、支付等等一大批的服务,前端怎么调用呢?和每个服务一个个打 交道?这显然是不可能的,这就需要有一个角色充当所有请求的入口,这个角色就是服务网关(API gateway)

    zuul优点:监控各个微服务、统一认证处理、减少客户端与各个微服务的交互次数......

    2、如何使用

    使用zuul首先要搭建好eureka服务,然后创建项目,此项目也要继承eureka的pom工程

    2.1、导入依赖

    <!--配置eureka的客户端-->
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
    </dependency>
    
    <!--支持zuui组件网关-->
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-netflix-zuul</artifactId>
    </dependency>
    

    2.2、全局配置文件

    spring:
      application:
        name: zuul01
    server:
      port: 9000
      #eureka的基本信息
    eureka:
      instance:
        hostname: 127.0.0.1
      client:
        service-url:
          defaultZone: http://127.0.0.1:7001/eureka/
        #它本身是一个普通的服务,需要在eureka-server注册
        register-with-eureka: true
        #需要获取注册信息
        fetch-registry: true
    
    #配置服务路由
    zuul:
      routes:
        api-dept-consumer:
          #访问服务的路径
          path: /api-a-service/**
          #指明上述的路径访问那些服务
          serviceId: ASERVER
        api-dept-prodvider:
          path: /api-b-service/**
          serviceId: BSERVER
    

    启动类添加@EnableZuulProxy注解,启动zuul,浏览器就可以访问对应服务了

    记得快乐
  • 相关阅读:
    算法技巧之打表
    Python_爬虫_爬取网络图片信息01
    python_爬虫_爬取京东商品信息
    Python——turtle库学习
    Python学习笔记——函数
    131219流水账
    121219流水账
    081219~111219流水账
    071219流水账
    061219流水账
  • 原文地址:https://www.cnblogs.com/Y-wee/p/14140439.html
Copyright © 2011-2022 走看看