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;
    }
    }

  • 相关阅读:
    linux 下查看网速的方法 (不需要安装任何软件)
    Raspberry Pi Kernel Compilation 内核编译官方文档
    Kernel compiling for Pi 2
    从源码编译rpi的内核
    设备驱动调试和移植的一般方法
    爸爸的歌
    表扬?批评?
    日历插件js,jquery
    zepto jquery和zepto的区别?
    怎么学习PS快?
  • 原文地址:https://www.cnblogs.com/a8457013/p/7736038.html
Copyright © 2011-2022 走看看