zuul的使用,过滤规则配置

LD is tigger forever,CG are not brothers forever, throw the pot and shine forever.
Modesty is not false, solid is not naive, treacherous but not deceitful, stay with good people, and stay away from poor people.
talk is cheap, show others the code,Keep progress,make a better result.

目录

概述

架构特性

设计思路

实现思路分析

1.创建项目

创建一个 Maven 项目 zuul-demo,在 pom.xml 中增加 Spring Cloud 项目的依赖,然后加入 Zuul 的依赖,代码如下所示。

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-netflix-zuul</artifactId>
</dependency>

属性文件中增加配置信息:

2.家配置信息

spring.application.name=zuul-demo
server.port=2103

zuul.routes.biancheng.path=/biancheng/**
zuul.routes.biancheng.url=http://c.biancheng.net

3.配置启动程序

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

通过 zuul.routes 来配置路由转发,biancheng 是自定义的名称,当访问 biancheng/** 开始的地址时,就会跳转到 http://c.biancheng.net 上。比如输入地址为“http://localhost:2103/biancheng/abc”

集成 Eureka

在实际使用中我们通常是用 Zuul 来代理请求转发到内部的服务上去,统一为外部提供服务。

在实际使用中我们通常是用 Zuul 来代理请求转发到内部的服务上去,统一为外部提供服务。

首先需要添加 Eureka 的依赖,代码如下所示。

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>

eureka.client.serviceUrl.defaultZone=http://zhangsan:123456@localhost:8761/eureka/

重启服务,我们可以通过默认的转发规则来访问 Eureka 中的服务。访问规则是“API 网关地址+访问的服务名称+接口 URI”。

相关工具如下:

实验效果:(解决思路)

分析:

小结:

主要讲述了一些Spring Cloud Config使用详解,里面有许多不足,请大家指正~

参考资料和推荐阅读

1.链接: 参考资料.
2.链接: 参考资料.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

执于代码

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值