############Zuul简单使用################

1、pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<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>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.test</groupId>
<artifactId>eureka-client-feign-hystrix-zuul</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>eureka-client-feign-hystrix-zuul</name>
<description>Demo project for Spring Boot</description> <properties>
<java.version>1.8</java.version>
<spring-cloud.version>Greenwich.SR1</spring-cloud.version>
</properties> <dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
</dependency> <dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-zuul</artifactId>
</dependency>
</dependencies> <dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement> <build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build> </project>

2、添加注解

package com.test.eurekaclientfeign;

import com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsStreamServlet;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.netflix.hystrix.EnableHystrix;
import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;
import org.springframework.cloud.netflix.zuul.EnableZuulProxy;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean; @SpringBootApplication
@EnableFeignClients
@EnableCircuitBreaker
@EnableHystrixDashboard
@EnableHystrix
@EnableZuulProxy
public class EurekaClientFeignHystrixZuulApplication {
public static void main(String[] args) {
SpringApplication.run(EurekaClientFeignHystrixZuulApplication.class, args);
} @Bean
public ServletRegistrationBean getServlet(){
HystrixMetricsStreamServlet streamServlet = new HystrixMetricsStreamServlet();
ServletRegistrationBean registrationBean = new ServletRegistrationBean(streamServlet);
registrationBean.setLoadOnStartup(1);
registrationBean.addUrlMappings("/actuator/hystrix.stream");
registrationBean.setName("HystrixMetricsStreamServlet");
return registrationBean;
}
}

3、application.yml配置文件

spring:
application:
name: eureka-client-feign-hystrix-zuul #应用名
logging: #logging日志配置
level:
root: INFO
org.hibernate: INFO
server:
port: 8669 #服务端口 eureka:
instance:
hostname: localhost
prefer-ip-address: true
instance-id: ${spring.application.name}:${spring.application.instance_id:${server.port}}
client:
serviceUrl:
defaultZone: http://${eureka.instance.hostname}:8661/eureka
management:
endpoints:
web:
exposure:
include: '*'
endpoint:
health:
show-details: always

这样就完成了,只是这种方式访问,需要添加serviceID访问

例如:

#不使用Zuul访问
http://192.168.137.1:8664/user/1 #使用Zuul访问,其中eureka-client-user为serviceId
http://192.168.137.1:8669/eureka-client-user/user/4

###############自己配置Zuul##################

在application.yml添加如下的配置

spring:
application:
name: eureka-client-feign-hystrix-zuul #应用名
logging: #logging日志配置
level:
root: INFO
org.hibernate: INFO
server:
port: 8669 #服务端口 eureka:
instance:
hostname: localhost
prefer-ip-address: true
instance-id: ${spring.application.name}:${spring.application.instance_id:${server.port}}
client:
serviceUrl:
defaultZone: http://${eureka.instance.hostname}:8661/eureka
management:
endpoints:
web:
exposure:
include: '*'
endpoint:
health:
show-details: always
zuul:
routes:
eureka-client-user: /myuser/** #将serviceID = eureka-client-user 简化为 /myuser

第九章 SpringCloud之Zuul路由的更多相关文章

  1. java框架之SpringCloud(6)-Zuul路由网关

    介绍 Zuul 包含了对请求的路由和过滤两个最重要的功能: 其中路由功能服务将外部请求转发到具体的微服务实例上,是实现外部访问统一入口的基础.而过滤的功能则负责对请求的处理过程进行干预,是实现请求校验 ...

  2. Spring-Cloud之Zuul路由网关-6

    一.为什么需要Zuul? Zuul 作为微服务系统的网关组件,用于构建边界服务( Edge Service ),致力于动态路由.过滤.监控.弹性伸缩和安全.Zuul 作为路由网关组件,在微服务架构中有 ...

  3. SpringCloud:Zuul路由配置超时问题

    测试访问时长 修改下业务类,增加sleep休眠时长,以此查看Zuul的熔断 @GetMapping("/test1") public Object test1() { try { ...

  4. 实战SpringCloud响应式微服务系列教程(第九章)使用Spring WebFlux构建响应式RESTful服务

    本文为实战SpringCloud响应式微服务系列教程第九章,讲解使用Spring WebFlux构建响应式RESTful服务.建议没有之前基础的童鞋,先看之前的章节,章节目录放在文末. 从本节开始我们 ...

  5. SpringCloud系列——Zuul 动态路由

    前言 Zuul 是在Spring Cloud Netflix平台上提供动态路由,监控,弹性,安全等边缘服务的框架,是Netflix基于jvm的路由器和服务器端负载均衡器,相当于是设备和 Netflix ...

  6. SpringCloud 进阶之Zuul(路由网关)

    1. Zuul(路由网关) Zuul 包含了对请求的路由和过滤两个最主要的功能; 路由功能:负责将外部请求转发到具体的微服务实例上,是实现外部访问统一入口的基础; 过滤功能:负责对请求的处理过程进行干 ...

  7. SpringCloud学习系列之七 ----- Zuul路由网关的过滤器和异常处理

    前言 在上篇中介绍了SpringCloud Zuul路由网关的基本使用版本,本篇则介绍基于SpringCloud(基于SpringBoot2.x,.SpringCloud Finchley版)中的路由 ...

  8. SpringCloud的入门学习之概念理解、Zuul路由网关

    1.Zuul路由网关是什么? 答:Zuul包含了对请求的路由和过滤两个最主要的功能,其中路由功能负责将外部请求转发到具体的微服务实例上,是实现外部访问统一入口的基础而过滤器功能则负责对请求的处理过程进 ...

  9. SpringCloud学习笔记(八):Zuul路由网关

    概述 是什么? Zuul包含了对请求的路由和过滤两个最主要的功能: 其中路由功能负责将外部请求转发到具体的微服务实例上,是实现外部访问统一入口的基础而过滤器功能则负责对请求的处理过程进行干预,是实现请 ...

随机推荐

  1. 基于 Debian 的 Netrunner 19.08 “Indigo” 发布

    Netrunner 19.08版本被称为“Indigo”,基于最近发布的Debian GNU/Linux 10 “Buster”操作系统系列,具有KDE Plasma 5.14.5桌面环境,并附带KD ...

  2. target_link_libraries每次能连接1个???

    target_link_libraries(usb-1.0)target_link_libraries(cyusb)

  3. 【CF750E】New Year and Old Subsequence

    题目大意:给定一个长度为 N 的字符串,定义一个字串是"好的",当且仅当字串中含有一个 "2017" 的子序列,且不含有 "2016" 的子 ...

  4. cookie的使用以及cookie的跨域名获取

    cookie存放容量4k左右,可设置过期时间. 1.cookie的封装使用 //设置cookies function setCookie(name, value) { var Days = 30; v ...

  5. beanFactory & FactoryBean区别

    FactoryBean Spring内部实现的一种规范& 开头作为beanName Spring中所有的容器都是FactoryBean 因为容器本身也由容器管理, root来创建 都是单列在I ...

  6. GitHub入门和项目托管

    (博主原创文章,转载请注明出处: http://www.cnblogs.com/xianlei/git) 前言: 本文目标: Git入门,能够在Github托管项目,能够进行实际项目开发 本文主要内容 ...

  7. std::setw(size)与std::setfill(char)

    头文件:#include <iostream>#include <iomanip>using namespace std; 功能:  std::setw :需要填充多少个字符, ...

  8. buuctf@helloword

  9. vuex中mapState、mapMutations、mapAction的理解

    当一个组件需要获取多个状态时候,将这些状态都声明为计算属性会有些重复和冗余.为了解决这个问题,我们可以使用 mapState 辅助函数帮助我们生成计算属性. // 在单独构建的版本中辅助函数为 Vue ...

  10. CSS3 3D转换——rotateX(),rotateY(),rotateZ()

    CSS3 允许使用 3D 转换来对元素进行格式化. ㈠浏览器支持 Internet Explorer 10 和 Firefox 支持 3D 转换. Chrome 和 Safari 需要前缀 -webk ...