【Spring Cloud】Zuul 路由访问

本节大纲:
- 简介
- 架构图
- 创建项目(接着上一章节)
- 在Fcat实战项目中的应用

简介

zuul是Netflix出品的一个基于JVM路由和服务端的负载均衡器。
类似nginx,反向代理的功能,增加了一些配合其他组件的特性。
Spring Cloud Zuul路由是微服务架构的不可或缺的一部分,提供动态路由,监控,弹性,安全等的边缘服务。

Zuul功能
  • 认证
  • 压力测试
  • 金丝雀测试
  • 动态路由
  • 负载削减
  • 安全
  • 静态响应处理
  • 主动/主动交换管理

架构图

这里写图片描述

创建项目

关键代码

引入zuul包
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-zuul</artifactId>
</dependency>
开启zuul路由

在启动类中,通过注解来开启zuul路由

@EnableZuulProxy
配置Zuul
zuul:
  routes:
    fcat-user:
      path: /fcat-user/**
      serviceId: fcat-user
创建controller

在用户模块中,创建DictController

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("dict")
public class DictController {

    @GetMapping(value = "getDict")
    public String getDict(){
        return "fcat-user dict";
    }
}

启动访问

依次启动:CenterApplication、UserApplication、GateApplication
访问测试:http://localhost:8762/fcat-user/dict/getDict

在Fcat项目中的应用

这里写图片描述

源码地址:https://gitee.com/xfdm_admin/spring-cloud/tree/master
更多相关内容请查看:
angular、spring cloud 开源实战项目源码:https://gitee.com/xfdm/FCat
QQ群:549141844

代码持续更新…

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

FCAT.TOP

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

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

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

打赏作者

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

抵扣说明:

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

余额充值