当前位置:网站首页>[microservices openfeign] two degradation methods of feign | fallback | fallbackfactory
[microservices openfeign] two degradation methods of feign | fallback | fallbackfactory
2022-07-04 04:21:00 【Bulst】
List of articles
Above, we are right @FeignClient Made a detailed introduction , Next , Let's come together feign Two degradation methods .
fallbackFactory recommend : You can catch exception information and return the default degradation result . Stack information can be printed .
Fallback
Fault tolerant class
import com.ossa.feign.api.producer.ProducerFeign;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
/** * @author issavior */
@Slf4j
@Service
public class ProducerFeignFallback implements ProducerFeign {
@Override
public String producerById(String id) {
String msg = "fallback Current limiting method ";
return id + msg;
}
}
FeignClient
import com.ossa.feign.config.FeignClientConfig;
import com.ossa.feign.fallback.ProducerFeignFallback;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
/** * @author issavior */
@FeignClient(value = "ossa-service-producer", configuration = FeignClientConfig.class,fallback = ProducerFeignFallback.class)
public interface ProducerFeign {
/** * according to ID Query products * * @param id The primary key of the item ID * @return Information about related products */
@GetMapping(value = "/producer/{id}")
String producerById(@PathVariable("id") String id);
}
FallbackFactory
Fault tolerant class
import com.ossa.feign.api.producer.ProducerFeign;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
/** * @author issavior */
@Slf4j
@Service
public class ProducerFeignFallback implements FallbackFactory<ProducerFeign> {
@Override
public ProducerFeign create(Throwable throwable) {
return id -> {
log.info(" The error is :{}", throwable.getMessage());
String msg = "fallback Current limiting method ";
return id + msg;
};
}
}
FeignClient
import com.ossa.feign.config.FeignClientConfig;
import com.ossa.feign.fallback.ProducerFeignFallback;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
/** * @author issavior */
@FeignClient(value = "ossa-service-producer", configuration = FeignClientConfig.class,fallbackFactory = ProducerFeignFallback.class)
public interface ProducerFeign {
/** * according to ID Query products * * @param id The primary key of the item ID * @return Information about related products */
@GetMapping(value = "/producer/{id}")
String producerById(@PathVariable("id") String id);
}
边栏推荐
- RHCSA 01 - 创建分区与文件系统
- Ppt tutorial, how to save a presentation as a PDF file in PowerPoint?
- Introduction to asynchronous task capability of function calculation - task trigger de duplication
- Distributed system: what, why, how
- Smart subway | cloud computing injects wisdom into urban subway transportation
- idea修改主体颜色
- Huawei cloud Kunpeng engineer training (Guangxi University)
- Understand the principle of bytecode enhancement technology through the jvm-sandbox source code
- Programmers' telecommuting is mixed | community essay solicitation
- My opinion on how to effectively telecommute | community essay solicitation
猜你喜欢

Flink learning 8: data consistency
![Cesiumjs 2022^ source code interpretation [0] - article directory and source code engineering structure](/img/ba/c1d40de154344ccc9f2fd1dd4cb12f.png)
Cesiumjs 2022^ source code interpretation [0] - article directory and source code engineering structure

Restore the subtlety of window position

Confession code collection, who says program apes don't understand romance
![[Logitech] m720](/img/bb/44144a1c3907808398c05b3b36962c.png)
[Logitech] m720

Mitsubishi M70 macro variable reading Mitsubishi M80 public variable acquisition Mitsubishi CNC variable reading acquisition Mitsubishi CNC remote tool compensation Mitsubishi machine tool online tool

还原窗口位置的微妙之处

2021 RSC | Drug–target affinity prediction using graph neural network and contact maps

Perf simple process for multithreaded profile

Graduation project: design seckill e-commerce system
随机推荐
程序员远程办公喜忧参半| 社区征文
Redis cluster uses Lua script. Lua script can also be used for different slots
透过JVM-SANDBOX源码,了解字节码增强技术原理
Balance between picture performance of unity mobile game performance optimization spectrum and GPU pressure
vim正确加区间注释
[Yugong series] go teaching course 002 go language environment installation in July 2022
Unity draws the trajectory of pinball and billiards
Pytest multi process / multi thread execution test case
网络 - VXLAN
R语言中如何查看已安装的R包
三年进账35.31亿,这个江西老表要IPO了
北漂程序员,月薪20K,一年攒15W,正常吗?
leetcode刷题:二叉树09(二叉树的最小深度)
LNK2038 检测到“RuntimeLibrary”的不匹配项: 值“MD_DynamicRelease”不匹配值“MDd_DynamicDebug”(main.obj 中)
Distributed system: what, why, how
Smart subway | cloud computing injects wisdom into urban subway transportation
How to add custom API objects in kubernetes (1)
leetcode刷题:二叉树06(对称二叉树)
ctf-pikachu-XSS
DP83848+网线热拔插