zoukankan      html  css  js  c++  java
  • zuul的多版本配置

    网关cloud-zuul->访问service-sms
    网关zuul{ip+port}:localhost:9100
    zuul要分发的后续服务名:service-sms

    启动类上添加代理

    @EnableZuulProxy
    

    配置一:

    server:
      port: 9100
    
    spring:
      application:
        name: cloud-zuul
      #数据库连接配置
      datasource:
        #配置当前使用的数据源的操作类型
        type: com.alibaba.druid.pool.DruidDataSource
        #配置MySQL的驱动程序类
        driver-class-name: com.mysql.cj.jdbc.Driver
        #数据库连接地址
        url: jdbc:mysql://192.168.1.113:3306/online-taxi-three?characterEncoding=UTF-8&serverTimezone=Asia/Shanghai
        #数据库连接用户名
        username: root
        #数据库连接密码
        password: 123456
        #进行数据库连接池的配置
        dbcp2:
          #初始化提供的连接数
          initial-size: 5
          #数据库连接池的最小维持连接数
          min-idle: 5
          #最大的连接数
          max-total: 5
          #等待连接获取的最大超时时间
          max-wait-millis: 200
          validation-query: SELECT 1
          test-while-idle: true
          test-on-borrow: false
          test-on-return: false
    
    #mybatis配置
    mybatis:
      mapper-locations:
        - classpath:mapper/*.xml
    
    eureka:
      client:
        service-url:
          defaultZone: http://eureka-7900:7900/eureka
      instance:
        hostname: localhost
        instance-id: online-taxi-zuul
    
    management:
      endpoints:
        web:
          exposure:
            include: "*"
      endpoint:
        health:
          ##默认是never
          show-details: ALWAYS
          enabled: true
        routes:
          enabled: true
    
    logging:
      level:
        com.netflix: debug
        org.springframework: DEBUG
    

    配置二:给真实的服务名映射虚拟名

    zuul:
      routes:
        #此处名字随便取
        custom-zuul-name:
          path: /zuul-custom-name/**
          service-id: service-sms
    

    修改前访问方式:

    http://localhost:9100/service-sms/test/sms-test3
    

    修改后访问方式:

    http://localhost:9100/zuul-custom-name/test/sms-test3
    

    配置三:前缀

    zuul:
      prefix: /api
      # 是否移除前缀
      strip-prefix: true
      routes:
        api-passenger: /zuul-api-passenger/**
        api-driver: /zuul-api-driver/**
    

    配置三:忽略

    # 忽略
    # 演示功能:
    # 1、忽略服务名访问
    # 2、忽略正则
    
    
    zuul:
      routes:
        api-passenger: /zuul-api-passenger/**
        api-driver: /zuul-api-driver/**
      ignored-services:
      - service-sms
      ignored-patterns: 
      - /*-driver/**
    

    修改前访问方式:

    http://localhost:9100/service-sms/test/sms-test3
    

    修改后不能通过service-sms去访问

    配置四:敏感信息

    # 敏感
    # 演示功能:
    # 1、设置敏感
    
    
    zuul:
      routes:
        api-passenger: /zuul-api-passenger/**
        api-driver: /zuul-api-driver/**
      # 以下配置,表示token的值不向后面的微服务传播。以下配置为空表示:所有请求头都透传到后面微服务。
      sensitive-headers: token
    

    配置五:服务名配置

    # 服务名配置
    # 演示功能:
    # 1、服务名配置
    zuul:
      routes:
        service-sms: /zuul-service-sms/**
    

    修改前访问方式:

    http://localhost:9100/service-sms/test/sms-test3
    

    修改后访问方式:

    http://localhost:9100/zuul-service-sms/test/sms-test3
    

    配置六:自定义服务名配置

    # 自定义服务名
    # 演示功能:
    # 1、自定义服务名配置
    
    
    zuul:
      routes:
        #此处名字随便取
        custom-zuul-name:
          path: /zuul-custom-name/**
          # 这样配置负载均衡就失效了
          url: http://localhost:8091/
    

    修改前访问方式:

    http://localhost:9100/service-sms/test/sms-test3
    

    修改后访问方式:

    http://localhost:9100/zuul-custom-name/test/sms-test3
    

    配置七:自定义服务名配置、负载均衡

    # 自定义服务名配置 负载均衡
    # 演示功能:
    # 1、自定义服务名 负载均衡
    
    
    zuul:
      routes:
        #此处名字随便取
        custom-zuul-name: 
          path: /zuul-custom-name/**
          service-id: no-eureka-api-driver
          #不是eureka的service-id,我们自定义的,随便写的      
    no-eureka-api-driver:
      ribbon: 
        listOfServers: localhost:8091,localhost:8092
    ribbon: 
      eureka:
        enabled: false 
    
  • 相关阅读:
    开源博客平台WordPress十岁啦!
    (转载)C# Attribute 用法备忘
    hibernate入门
    Hibernate对象关系映射基础
    struts2UI标签
    struts2文件上传2(多文件)
    struts2验证(手工)
    通过修改注册表改变txt文件的默认打开方式
    struts2验证(XML)
    Struts国际化
  • 原文地址:https://www.cnblogs.com/zheaven/p/15513522.html
Copyright © 2011-2022 走看看