SpringCloud之zuul搭建

Easter79
• 阅读 512

一、zuul简介

Zuul的主要功能是路由和过滤器。路由功能是微服务的一部分,比如/api/user映射到user服务,/api/shop映射到shop服务。zuul实现了负载均衡。

zuul有以下功能:

  • Authentication
  • Insights
  • Stress Testing
  • Canary Testing
  • Dynamic Routing
  • Service Migration
  • Load Shedding
  • Security
  • Static Response handling
  • Active/Active traffic management

二、jar包依赖

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.pkfare</groupId>
    <artifactId>zuul</artifactId>
    <version>1.0.0</version>
    <packaging>jar</packaging>



    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.9.RELEASE</version>
    </parent>
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>Dalston.SR5</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-zuul</artifactId>
        </dependency>
    </dependencies>
    <build>
        <resources>
            <resource>
                <directory>src/main/java</directory>
            </resource>
            <resource>
                <directory>src/main/resources</directory>
            </resource>
        </resources>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

 三、启动程序

package com.pkfare.zuul;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.zuul.EnableZuulProxy;

@EnableZuulProxy
@SpringBootApplication
public class Application 
{
    public static void main( String[] args )
    {
        SpringApplication.run(Application.class, args);
    }
}

四、配置文件

#配置忽略的请求头
zuul.sensitive-headers=  
#配置对应的路由映射
zuul.routes.usercenter-provider.stripPrefix=false
zuul.routes.usercenter-provider.path=/user/**
zuul.routes.usercenter-provider.serviceId=USERCENTER-PROVIDER
#熔断时间
hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds=120000
#熔断信号量
zuul.semaphore.maxSemaphores=1000

#服务超时间
ribbon.ReadTimeout=180000
ribbon.ConnectTimeout=18000
点赞
收藏
评论区
推荐文章
Easter79 Easter79
2年前
springboot2.0下的zuul路由网关初探
Zuul作为微服务系统的网关组件,用于构建边界服务,致力于动态路由、过滤、监控、弹性伸缩和安全。为什么需要ZuulZuul、Ribbon以及Eureka结合可以实现智能路由和负载均衡的功能;网关将所有服务的API接口统一聚合,统一对外暴露。外界调用API接口时,不需要知道微服务系统中各服务相互调用的复杂性,保护了内部微服务单元的API接口;网关可以做
Stella981 Stella981
2年前
Spring Cloud系列教程(九):服务网关Zuul(Finchley版本)
一、前言Zuul是netflix开源的一个API网关服务器,其本质上是一个webservlet应用。Zuul是在云平台上提供动态路由,监控,弹性,安全等边缘服务的框架。Zuul相当于是PC、APP、H5等客户端和Netflix流应用的Web网站后端所有请求的前门,Zuu
Easter79 Easter79
2年前
SpringCloud负载均衡笔记
SpringCloud的负载均衡组件用的是Ribbon,这个东西就是服务消费者。它只是一个配置用的中转器,放在Zuul和 EurekaClient之间用来转发的,它里面写了好多规则,用来指定负载的规则。首先,Zuul:application.ymleureka:client:serviceUrl:
Easter79 Easter79
2年前
SpringCloud系列——Zuul 动态路由
  前言  Zuul是在SpringCloudNetflix平台上提供动态路由,监控,弹性,安全等边缘服务的框架,是Netflix基于jvm的路由器和服务器端负载均衡器,相当于是设备和Netflix流应用的Web网站后端所有请求的前门。本文基于上篇(SpringCloud系列——Ribbon负载均衡(https://www.
Stella981 Stella981
2年前
Nepxion Discovery 5.5.0 发布
!(https://oscimg.oschina.net/oscnet/f81c043194ef4732880459d00c1a720e.png)发布日志功能更新:增加基于Opentracing调用链的支持,目前支持UberJaeger,实现在SpringCloudGateway、Zuul和服务上的灰度
Easter79 Easter79
2年前
SpringCloud从入门到进阶——单点部署Zuul的压力测试与调优(一)
前言说明:通过zuul访问后端服务时,这个流程是如何的?当你用500线程并发访问zuul和用100线程并发访问zuul,zuul分别会用多少个线程去并发访问后端的服务?后端最多能承受多少个并发线程?zuul默认是Hystrix的信号量隔离,这个值对zuul并发访问后端时有什么影响?可以通过这一篇来了解一下。内容  作为微服务架构系统的入口,毫无疑
Stella981 Stella981
2年前
Spring Cloud Zuul 那些你不知道的功能点
本文摘自于《SpringCloud微服务入门实战与进阶》一书。1./routes端点当@EnableZuulProxy与SpringBootActuator配合使用时,Zuul会暴露一个路由管理端点/routes。借助这个端点,可以方便、直观地查看以及管理Zuul的路由。将所有端点都暴露出来,增加下面的配置:
Easter79 Easter79
2年前
SpringCloud微服务(05):Zuul组件,实现路由网关控制
一、Zuul组件简介1、基础概念Zuul网关主要提供动态路由,监控,弹性,安全管控等功能。在分布式的微服务系统中,系统被拆为了多个微服务模块,通过zuul网关对用户的请求进行路由,转发到具体的后微服务模块中。2、Zuul的作用1)按照不同策略,将请求转发到不同的服务上去;
Easter79 Easter79
2年前
SpringCloud(第 018 篇)Zuul 服务 API 网关微服务之代理与反向代理
SpringCloud(第018篇)Zuul服务API网关微服务之代理与反向代理一、大致介绍1、API服务网关顾名思义就是统一入口,类似nginx、F5等功能一样,统一代理控制请求入口,弱化各个微服务被客户端记忆功能;
Easter79 Easter79
2年前
SpringCloud学习笔记(七)之路由网关Zuul
是什么Zuul包含了对请求路由和过滤两个最主要的功能:其中路由功能负责将外部请求转发到具体的微服务实例上,是实现外部访问统一入口的基础。而过滤功能则负责对请求的处理过程进行干预,是实现请求校验、服务聚合等功能的基础。Zuul和Eureka进行整合,将zuul自身注册为Eureka服务治理下的应用,同时从Eureka中获得其他微
Easter79
Easter79
Lv1
今生可爱与温柔,每一样都不能少。
文章
2.8k
粉丝
5
获赞
1.2k