springcloud:3.6测试信号量隔离

服务提供者【test-provider8001】

Openfeign远程调用服务提供者搭建

文章地址http://t.csdnimg.cn/06iz8

相关接口

测试远程调用:http://localhost:8001/payment/index

服务消费者【test-consumer-resilience4j8004】

Openfeign远程调用消费者搭建

文章地址http://t.csdnimg.cn/06iz8

依赖

java 复制代码
 <!-- resilience4j隔离依赖  -->
        <dependency>
            <groupId>io.github.resilience4j</groupId>
            <artifactId>resilience4j-bulkhead</artifactId>
            <version>1.7.0</version>
        </dependency>
        <!-- resilience4j  -->
        <dependency>
            <groupId>io.github.resilience4j</groupId>
            <artifactId>resilience4j-spring-cloud2</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-circuitbreaker-resilience4j</artifactId>
        </dependency>

application.yml

java 复制代码
resilience4j:
  #信号量隔离
  bulkhead:
    instances:
      # 实例名称:自己定义的名称,对应@Bulkhead的name
      backendA:
        # 隔离允许并发线程执行的最大数量
        maxConcurrentCalls: 5
        # 当达到并发调用数量时,新的线程的阻塞时间
        maxWaitDuration: 20ms

OrderController【控制层】

java 复制代码
 /**
     * 测试信号量隔离
     *
     * @return
     */
    @GetMapping("/bulkhead")
    @Bulkhead(name = "backendA", type = Bulkhead.Type.SEMAPHORE)
    //name:对应的配置名,type:隔离类型-信号量/线程
    public String bulkhead() throws InterruptedException {
        log.info("************** 进入方法 *******");
        TimeUnit.SECONDS.sleep(10);
        String index = paymentFeignService.paymentIndex();
        log.info("************** 离开方法 *******");
        return index;
    }

相关接口

测试信号量隔离:http://localhost:8004/order/bulkhead

jmeter测试思路

此配置隔离并发线程最大数量为5,所以jmeter我们采用大于5个线程进行测试

相关推荐
NE_STOP1 分钟前
SpringCloud进阶--RabbitMQ消息队列(完结)
spring
studyForMokey9 分钟前
【Android面试】RecylerView专题
android·spring·面试
Java成神之路-31 分钟前
Spring AOP 注解开发实战:无侵入式功能增强从入门到精通(Spring系列7)
spring
lizhongxuan39 分钟前
LLM Wiki:让大模型替你打理知识库的完整指南
前端·后端·面试
老马95271 小时前
opencode2-初步体验
人工智能·后端
常利兵1 小时前
细说API:颠覆认知!重新认识RESTful的真正精髓
后端·restful
她说..1 小时前
Java 注解核心面试题
java·spring boot·spring·spring cloud·自定义注解
镜花水月linyi1 小时前
JDK 8 → 17 → 21 → 25:一次性讲清四代版本的关键跃迁
java·后端
啷里格啷2 小时前
Day5 【补充】线程模型与异步处理
后端
Java水解2 小时前
Spring Security 最佳实践:2026 实战指南
后端