• SpringCloud四:hystrix-propagation


    注:pom.xml 及配置文件配置与上篇相同

    package com.itmuch.cloud.controller;

    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.web.bind.annotation.GetMapping;
    import org.springframework.web.bind.annotation.PathVariable;
    import org.springframework.web.bind.annotation.RestController;
    import org.springframework.web.client.RestTemplate;
    import org.springframework.web.context.annotation.SessionScope;

    import com.itmuch.cloud.entity.User;
    import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
    import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
    /**
    * 短路器第二天
    * @author z
    *
    */
    @RestController
    public class MovieController {
    @Autowired
    private RestTemplate restTemplate;

    @GetMapping("/movie/{id}")
    //表示@HystrixCommand与findById方法会在同一个线程中调用
    //如果不配合的话findById是一个线程,@HystrixCommand是一个隔离的线程相当于两个线程
    //正常情况下不需要配置,等抛异常了在配置
    @HystrixCommand(fallbackMethod = "findByIdFallback", commandProperties = @HystrixProperty(name = "execution.isolation.strategy", value = "SEMAPHORE"))
    public User findById(@PathVariable Long id) {
    return this.restTemplate.getForObject("http://microservice-provider-user/simple/" + id, User.class);
    }

    public User findByIdFallback(Long id) {
    User user = new User();
    user.setId(0L);
    return user;
    }
    }

  • 相关阅读:
    XDebug的配置和使用
    PHP一致性hash
    命令注入绕过技巧总结
    Aireplay-ng 6 种常用攻击模式详解
    CDlinux无线审计工具使用
    Aircrack-ng无线审计工具使用
    Ubuntu中的mysql
    Centos安装python3.7时遇到的问题
    写程序的时候发现了个数学在线工具,感觉挺好,Gegebra
    OpenCV实现图像变换(python)-仿射变换原理
  • 原文地址:https://www.cnblogs.com/a8457013/p/7736038.html
Copyright © 2020-2023  润新知