6.Spring Cloud初相识-------Zool路由
前言:
在生产环境中,我们不可能将每个服务的真实信息暴漏出去,因为这样太不安全。
我们会选择使用路由代理真实的服务信息,由它负责转发给真实的服务。
新建一个Zool:
1.添加依赖
<?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><groupId>com.xm.cloud</groupId><artifactId>cl_zool</artifactId><version>0.0.1-SNAPSHOT</version><packaging>jar</packaging><name>cl_zool</name><description>This is a Web about springcloud</description><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.0.6.RELEASE</version><relativePath/> <!-- lookup parent from repository --></parent><properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding><java.version>1.8</java.version><spring-cloud.version>Finchley.SR2</spring-cloud.version></properties><dependencies><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-netflix-eureka-client</artifactId></dependency><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-netflix-zuul</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></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.修改配置
server.port=9090
spring.application.name=cl-zool-gatewayeureka.client.service-url.defaultZone=http://127.0.0.1:7001/eureka/
#服务名统一前缀
zuul.prefix=/xm
#所有服务真实名称隐藏
zuul.ignored-services="*"
zuul.routes.myHello.service-id=CL-HELLO-PRODUCER
zuul.routes.myHello.path=/myHello/**
3.开启注解
package com.xm.cloud;import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.zuul.EnableZuulProxy;@EnableDiscoveryClient
@EnableZuulProxy
@SpringBootApplication
public class ClZoolApplication {public static void main(String[] args) {SpringApplication.run(ClZoolApplication.class, args);}
}
测试:
开启eureka7001、服务生产者8001、路由zool9090
1.访问Eureka客户端:
2.访问服务生产者localhost:8001/hello
3.访问不加前缀真实服务名称http://localhost:9090/CL-HELLO-PRODUCER/hello:
4.访问加前缀真实服务名称http://localhost:9090/xm/CL-HELLO-PRODUCER/hello:
5.访问不加前缀路由服务名称http://localhost:9090/myHello/hello:
6.访问加前缀路由服务名称http://localhost:9090/xm/myHello/hello:
转载于:https://www.cnblogs.com/TimerHotel/p/springcloud_06.html
6.Spring Cloud初相识-------Zool路由相关推荐
- 基于Nacos配置中心实现Spring Cloud Gateway的动态路由管理
前面我们了解过了Sentinel 网关流量控制之Spring Cloud Gateway实战,今天带给大家是基于Nacos配置中心实现Spring Cloud Gateway的动态路由管理. 1.为什 ...
- 使用Nacos实现Spring Cloud Zuul的动态路由
一.前言 Nacos是阿里巴巴开源的致力于服务发现与管理.动态配置管理,以及动态DNS服务的中间件,目前已发布至0.5.0版本,除了与Spring Cloud更加紧密结合以外,还丧心病狂地支持JDK1 ...
- 基于Nacos实现Spring Cloud Gateway实现动态路由
简介 该文档主要介绍以Nacos为配置中心,实现Spring Cloud GateWay 实现动态路由的功能.Spring Cloud Gateway启动时候,就将路由配置和规则加载到内存里,无法做到 ...
- Spring Cloud Gateway –配置简单路由
可以将Spring Cloud Gateway视为Spring Cloud Netflix Zuul项目的后续产品,并有助于在微服务环境中实现Gateway模式 . 它建立在 Spring Boot ...
- Spring Cloud GateWay系列(三):路由规则动态刷新
Spring Cloud Gateway旨在提供一种简单而有效的方式来路由API,并为它们提供横切关注点,例如:安全性.监控/指标和弹性.Route(路由)是网关的基本单元,由唯一标识符ID.目标地址 ...
- spring cloud gateway 之 动态路由改造
目录 gateway本地文件常规路由配置 本地文件配置对业务造成的痛点 动态路由改造 1 gateway本地文件常规路由配置 我们先大致看下gateway中的常规概念 Route(路由):路由是网关的 ...
- spring cloud gateway 之动态路由
前面分别对 Spring Cloud Zuul 与 Spring Cloud Gateway 进行了简单的说明,它门是API网关,API网关负责服务请求路由.组合及协议转换,客户端的所有请求都首先经过 ...
- API 网关服务:Spring Cloud Zuul(二):路由详解、Cookie 与头信息
实践出于<Spring Cloud 微服务实战> - 瞿永超 著 路由详解 传统路由配置 传统路由配置就是在不依赖于服务发现机制的情况下,通过在配置文件中具体指定每个路由表达式与服务实 ...
- 三分钟了解Spring Cloud Gateway路由转发之自动路由
文章目录 一.前言 二.路由配置 1. 静态路由 2. 动态路由 3. 自动路由 三.Spring Cloud Gateway 是如何实现动态路由 工作原理 源码解析 路由转发原理 路由转发源码解析 ...
最新文章
- mysql让数据库的数据按照id来排序方法
- CSS margin详解
- 组合的json文件分隔或者拆分
- iOS再现安全漏洞 “1970变砖”问题仍未解决
- 会计用计算机很快是,40个超实用电脑快捷键,老会计都在用!
- 非平衡电桥电阻计算_直流双臂电桥使用方法,统统告诉你
- 2-15 复合类型概述
- 根据字体图片,查找下载Font字体
- 超级搜索术-朱丹-全部笔记整理
- 简单个人静态HTML网页设计作品——广西北海家乡旅游景点 10页 DIV布局个人介绍网页模板代码 DW个人网站制作成品 web网页制作与实现
- HDU 4435 charge-station (搜索+YY)
- Android wifi探究一:初步认识wpa_supplicant与wifi框架梳理
- 操作系统真实的虚拟内存是什么样的(一)
- 基于loongnix20系统,libvlc代码直接集成测试
- 如何以聪明的方式提问
- course83_lab2_8086的寻址方式
- Android: SQLite + ListView 实现 新闻 App
- Python大数据培训课程培训费用是多少
- MAC下搭建Hexo博客
- winform如何修改exe文件的图标
热门文章
- 输出字母在字符串中位置索引 python
- win10正式版新功能介绍
- 【Visual C++】游戏开发笔记四十 浅墨DirectX教程之八 绘制真实质感的三维世界 光照与材质专场
- 2022年618有哪些蓝牙耳机值得买?四款降噪效果好的蓝牙耳机测评
- 网络安全- 专访丨互联网安全城市巡回赛冠军肖策:“大满贯”背后的秘密
- silverlight,WPF动画终极攻略之会飞的小鸟篇(Blend 4开发)
- 优秀平面设计师是如何思考的?
- Kali Linux系统正确安装指南教程(一)MAC安装kail+Vmware Fusion详细教程(吐血本人测试10次)
- 密码加密解密(一)——摩斯密码
- 酷炫小程序相册源码,制作属于自己的相册,免费下载