SpringCloud之zuul搭建

一、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包依赖

1<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 2 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 3 <modelVersion>4.0.0</modelVersion> 4 5 <groupId>com.pkfare</groupId> 6 <artifactId>zuul</artifactId> 7 <version>1.0.0</version> 8 <packaging>jar</packaging> 9 10 11 12 <properties> 13 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 14 </properties> 15 16 <parent> 17 <groupId>org.springframework.boot</groupId> 18 <artifactId>spring-boot-starter-parent</artifactId> 19 <version>1.5.9.RELEASE</version> 20 </parent> 21 <dependencyManagement> 22 <dependencies> 23 <dependency> 24 <groupId>org.springframework.cloud</groupId> 25 <artifactId>spring-cloud-dependencies</artifactId> 26 <version>Dalston.SR5</version> 27 <type>pom</type> 28 <scope>import</scope> 29 </dependency> 30 </dependencies> 31 </dependencyManagement> 32 <dependencies> 33 <dependency> 34 <groupId>org.springframework.cloud</groupId> 35 <artifactId>spring-cloud-starter-zuul</artifactId> 36 </dependency> 37 </dependencies> 38 <build> 39 <resources> 40 <resource> 41 <directory>src/main/java</directory> 42 </resource> 43 <resource> 44 <directory>src/main/resources</directory> 45 </resource> 46 </resources> 47 <plugins> 48 <plugin> 49 <groupId>org.springframework.boot</groupId> 50 <artifactId>spring-boot-maven-plugin</artifactId> 51 </plugin> 52 <plugin> 53 <groupId>org.apache.maven.plugins</groupId> 54 <artifactId>maven-compiler-plugin</artifactId> 55 <configuration> 56 <source>1.8</source> 57 <target>1.8</target> 58 <encoding>UTF-8</encoding> 59 </configuration> 60 </plugin> 61 </plugins> 62 </build> 63</project>

 三、启动程序

1package com.pkfare.zuul; 2 3import org.springframework.boot.SpringApplication; 4import org.springframework.boot.autoconfigure.SpringBootApplication; 5import org.springframework.cloud.netflix.zuul.EnableZuulProxy; 6 7@EnableZuulProxy 8@SpringBootApplication 9public class Application 10{ 11 public static void main( String[] args ) 12 { 13 SpringApplication.run(Application.class, args); 14 } 15}

四、配置文件

1#配置忽略的请求头 2zuul.sensitive-headers= 3#配置对应的路由映射 4zuul.routes.usercenter-provider.stripPrefix=false 5zuul.routes.usercenter-provider.path=/user/** 6zuul.routes.usercenter-provider.serviceId=USERCENTER-PROVIDER 7#熔断时间 8hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds=120000 9#熔断信号量 10zuul.semaphore.maxSemaphores=1000 11 12#服务超时间 13ribbon.ReadTimeout=180000 14ribbon.ConnectTimeout=18000
点赞
收藏

评论区

加载中...

相关推荐

手写Java HashMap源码

HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22

springboot2.0下的zuul路由网关初探

Zuul作为微服务系统的网关组件,用于构建边界服务,致力于动态路由、过滤、监控、弹性伸缩和安全。为什么需要ZuulZuul、Ribbon以及Eureka结合可以实现智能路由和负载均衡的功能;网关将所有服务的API接口统一聚合,统一对外暴露。外界调用API接口时,不需要知道微服务系统中各服务相互调用的复杂性,保护了内部微服务单元的API接口;网关可以做

Spring Cloud系列教程(九):服务网关Zuul(Finchley版本)

一、前言Zuul是netflix开源的一个API网关服务器,其本质上是一个webservlet应用。Zuul是在云平台上提供动态路由,监控,弹性,安全等边缘服务的框架。Zuul相当于是PC、APP、H5等客户端和Netflix流应用的Web网站后端所有请求的前门,Zuu

SpringCloud负载均衡笔记

SpringCloud的负载均衡组件用的是Ribbon,这个东西就是服务消费者。它只是一个配置用的中转器,放在Zuul和 EurekaClient之间用来转发的,它里面写了好多规则,用来指定负载的规则。首先,Zuul:application.ymleureka:client:serviceUrl:

SpringCloud系列——Zuul 动态路由

  前言  Zuul是在SpringCloudNetflix平台上提供动态路由,监控,弹性,安全等边缘服务的框架,是Netflix基于jvm的路由器和服务器端负载均衡器,相当于是设备和Netflix流应用的Web网站后端所有请求的前门。本文基于上篇(SpringCloud系列——Ribbon负载均衡(https://www.

Nepxion Discovery 5.5.0 发布

!(https://oscimg.oschina.net/oscnet/f81c043194ef4732880459d00c1a720e.png)发布日志功能更新:增加基于Opentracing调用链的支持,目前支持UberJaeger,实现在SpringCloudGateway、Zuul和服务上的灰度