通过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动态配置,开始老的机器占比达,慢慢调整到新机器上,实现平滑迁移。

相关推荐
叶总没有会17 小时前
Gateway--网关
spring cloud·微服务·gateway
4SAPI1 天前
AI API Gateway平台哪个好?从架构视角看企业多模型网关选型与实践
java·大数据·人工智能·gateway·php
JJJennie7771 天前
大模型网关怎么选?MAI Gateway vs 开源方案全面对比
网关·开源·gateway·ai网关
栗子~~1 天前
SpringCloud Gateway 基于 Nacos 实现动态路由
java·spring cloud·gateway
Raas1002 天前
MAI Gateway(魔芋企业级AI网关)能力解析:AI网关能做故障转移吗?AI网关核心功能详解
大数据·人工智能·网关·ai·gateway·mai gateway
流烟默2 天前
网关 Sentinel 限流实战:API 分组、规则加载与全量匹配踩坑记
nacos·gateway·sentinel·流控规则
Joy T3 天前
从 Nginx 到 Gateway 再到微服务:一次 AI 请求的完整链路
nginx·微服务·gateway·controller·路由转发·ai service·接口错误排查
Thomas.Sir3 天前
第19课:Gateway过滤器、全局拦截、请求响应统一处理
spring cloud·gateway
Thomas.Sir4 天前
第18课:Gateway路由规则、内置谓词、自定义谓词实战
spring cloud·gateway
2601_962177305 天前
2026年AI API Gateway怎么选?我整理了6种方案的费用、稳定性和适用场景
网络·人工智能·深度学习·gateway