zoukankan      html  css  js  c++  java
  • 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;
    }
    }

  • 相关阅读:
    [转载]RTSP in Stagefright
    FFMPEG for WMA Build Script
    Merge AACExtractor from ICS to Froyo
    查看部署在Heroku上的项目信息
    About AudioSystem Mute
    C++标准转换运算符reinterpret_cast
    纯CSS动态效果的画廊
    基于正则表达式匹配的C++语法高亮度显示
    C++标准转换运算符static_cast
    C++标准转换运算符const_cast
  • 原文地址:https://www.cnblogs.com/a8457013/p/7736038.html
Copyright © 2011-2022 走看看