当前位置: 首页 > news >正文

微服务与网关

什么是网关

背景

单体项目中,前端只用访问指定的一个端口8080,就可以得到任何想要的数据

在这里插入图片描述

微服务项目中,ip是不断变化的,端口是多个的

在这里插入图片描述

解决方案:网关

网关:就是网络的关口,负责请求的路由、转发、身份校验

在这里插入图片描述
在这里插入图片描述

前段还是访问之前的端口8080即可

在这里插入图片描述

后端对于前端来说是透明的

在这里插入图片描述

网关的两种实现

网关是一种开发规范,实际的实现有两种:

  • 官方
  • 网飞公司

在这里插入图片描述

步骤

在这里插入图片描述

maven坐标

在hm-gateway模块的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">
    <parent>
        <artifactId>hmall</artifactId>
        <groupId>com.heima</groupId>
        <version>1.0.0</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>hm-gateway</artifactId>

    <properties>
        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>
    </properties>
    <dependencies>
        <!--common-->
        <dependency>
            <groupId>com.heima</groupId>
            <artifactId>hm-common</artifactId>
            <version>1.0.0</version>
        </dependency>
        <!--网关-->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-gateway</artifactId>
        </dependency>
        <!--nacos discovery-->
        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
        </dependency>
        <!--负载均衡-->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-loadbalancer</artifactId>
        </dependency>
    </dependencies>
    

相关文章:

  • 数仓:核心概念,数仓系统(ETL,数仓分层,数仓建模),数仓建模方法(星型模型,雪花模型,星座模型)和步骤
  • mongodb
  • 【Spring】什么是Spring?
  • Hive增量迁移方案与实操PB级
  • STM32系统架构介绍
  • 使用 LangChain 对接硅基流动(SiliconFlow)API:构建一个智能对话系统
  • SpringBoot分布式应用程序和数据库在物理位置分配上、路由上和数量上的最佳实践是什么?
  • 一文速览DeepSeek-R1的本地部署——可联网、可实现本地知识库问答:包括671B满血版和各个蒸馏版的部署
  • Python Pandas(11):Pandas 数据可视化
  • shell脚本自动安装MySQL8
  • 使用Redis实现分布式锁,基于原本单体系统进行业务改造
  • python-leetcode 31.K个一组翻转链表
  • Selenium常用自动化函数
  • Jenkins 通过 Execute Shell 执行 shell 脚本 七
  • 读取本地excel并生成map,key为第一列,value为第二列
  • leetcode:171. Excel 表列序号(python3解法)
  • 深入解析 STM32 GPIO:结构、配置与应用实践
  • DeepSeek 助力 Vue 开发:打造丝滑的通知栏(Notification Bar)
  • 网络模型分层与对比
  • PostgreSQL 备库的延迟问题
  • 辽宁援疆前指总指挥王敬华已任新疆塔城地委副书记
  • 老字号“逆生长”,上海制造的出海“蜜”钥
  • “9+2”复式票,浦东购彩者拿下体彩大乐透1153万头奖
  • 夜读丨母亲为燕子打开家门
  • 普京召开俄乌谈判筹备会议,拉夫罗夫、绍伊古等出席
  • 古巴外长谴责美国再次将古列为“反恐行动不合作国家”