通过gateway实现服务的平滑迁移

本文属于b站图灵课堂springcloud笔记系列。讲得好还不要钱,值得推荐。

配置下试试。

再之前库存工程,新增了一个测试类

java 复制代码
package org.tuling.tlmallstorage.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.atomic.AtomicInteger;

@RestController
public class UrlController {
    private Logger logger = LoggerFactory.getLogger(getClass());
    @Value("${abcd.url:dddd}")
    private String url;

    private static final AtomicInteger URL_COUNT = new AtomicInteger(0);
    private static final AtomicInteger NEW_URL_COUNT = new AtomicInteger(0);

    @GetMapping("/url")
    public String url(){
        int count = URL_COUNT.incrementAndGet();
        logger.info("url count:{}",count);
        return url;
    }

    @GetMapping("/new/url")
    public String newUrl(){
        int count = NEW_URL_COUNT.incrementAndGet();
        logger.info("new_url count:{}",count);
        return url;
    }
}

gateway 修改下application.yml

启动postman跑几百次,postman 得先把url save到collection,再从collection run ,设置迭代次数,这个不如jmeter方便。

观看下结果,大致符合设置权重:5:1.

官网的例子更直接:可以指定了机器。这样就是在nacos动态配置,开始老的机器占比达,慢慢调整到新机器上,实现平滑迁移。

相关推荐
库库林_沙琪马9 小时前
4、Gateway
gateway
全靠bug跑9 小时前
Spring Cloud Gateway 实战:统一鉴权与用户信息全链路透传
java·开发语言·gateway·拦截器
骚戴1 天前
架构设计之道:构建高可用的大语言模型(LLM) Enterprise GenAI Gateway
java·人工智能·架构·大模型·gateway·api
Maiko Star3 天前
Gateway网关拦截自定义header & 用户上下文打通实战
gateway·threadlocal
skywalk81636 天前
LLM API Gateway:使用Comate Spec Mode创建大模型调用中转服务器
服务器·人工智能·gateway·comate
我是小妖怪,潇洒又自在6 天前
springcloud alibaba(七)Gateway--服务网关
spring·spring cloud·gateway
boy快快长大9 天前
【Spring Cloud Alibaba】Gateway(一)
数据库·gateway
谷隐凡二10 天前
网关的核心概念及简单演进介绍
gateway
摇滚侠10 天前
2025最新 SpringCloud 教程,Gateway-过滤器-基本使用,笔记58
笔记·spring cloud·gateway