SpringCloud——网关

SpringCloud学习
1.IDEA创建父子项目
2.SpringCloud——Eureka
3.SpringCloud——注册服务
4.SpringCloud——获取服务(1.Ribbon)
5.SpringCloud——获取服务(1.Feign)
6.SpringCloud——服务链路追踪
7.SpringCloud——断路器
8.SpringCloud——断路器监控
9.SpringCloud——断路器聚合监控
10.SpringCloud——网关

1.为什么要使用网关

我们现在有两种微服务,分别是数据微服务和视图微服务。 他们有可能放在不同的 ip 地址上,有可能是不同的端口。
为了访问他们,就需要记录这些地址和端口。 而地址和端口都可能会变化,这就增加了访问者的负担。 所以这个时候,我们就可以用网关来解决这个问题。
在这里插入图片描述

2.创建子项目zuul
https://blog.csdn.net/m0_45025658/article/details/106433731

3.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.example</groupId>
    <artifactId>SpringCloud</artifactId>
    <version>0.0.1-SNAPSHOT</version>
  </parent>

  <artifactId>zuulTest</artifactId>
  <version>0.0.1-SNAPSHOT</version>

  <name>zuulTest</name>

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


</project>

4.启动类

package org.example;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.netflix.zuul.EnableZuulProxy;

@SpringBootApplication
@EnableZuulProxy
@EnableEurekaClient
@EnableDiscoveryClient
public class zuulApplication {
    public static void main( String[] args ) {
    
    new SpringApplication(zuulApplication.class).run(args);
    }
}

5.application.yml

zuul:
  routes:
    api-a:
      path: /api-data/**
      serviceId: PRODUCT-DATA-SERVICE
    api-b:
      path: /api-view/**
      serviceId: PRODUCT-VIEW-SERVICE-FEIGN

server:
  port: 8010

6.启动eureka-service,data-service,view-feign-service,zuul

然后访问

数据服务
http://localhost:8010/api-data/getProduct
在这里插入图片描述
视图服务
http://localhost:8010/api-view/products
在这里插入图片描述

详细信息请看:
https://how2j.cn/k/springcloud/springcloud-zuul/2045.html#nowhere

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值