当前位置:网站首页>[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);
}
边栏推荐
- Pytest multi process / multi thread execution test case
- 2021 RSC | Drug–target affinity prediction using graph neural network and contact maps
- Myslq delete followed by limit
- Katalon uses script to query list size
- Epidemic strikes -- Thinking about telecommuting | community essay solicitation
- Exercises in quantum mechanics
- Rhcsa-- day one
- 1289_ Implementation analysis of vtask suspend() interface in FreeRTOS
- Redis cluster view the slots of each node
- 北漂程序员,月薪20K,一年攒15W,正常吗?
猜你喜欢
Understand the principle of bytecode enhancement technology through the jvm-sandbox source code
[csrf-01] basic principle and attack and defense of Cross Site Request Forgery vulnerability
Graduation project: design seckill e-commerce system
Flink学习8:数据的一致性
Leetcode skimming: binary tree 04 (sequence traversal of binary tree)
Flink learning 7: application structure
R语言dplyr中的Select函数变量列名
Balance between picture performance of unity mobile game performance optimization spectrum and GPU pressure
ctf-pikachu-CSRF
10 reasons for not choosing to use free virtual hosts
随机推荐
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
User defined path and file name of Baidu editor in laravel admin
There is a problem that the package cannot be parsed in the like project
01 QEMU starts the compiled image vfs: unable to mount root FS on unknown block (0,0)
laravel admin里百度编辑器自定义路径和文件名
Katalon framework test web (XXVI) automatic email
Why is the probability of pod increasing after IPtable
毕业三年,远程半年 | 社区征文
Storage of MySQL database
2020 Bioinformatics | TransformerCPI
Evolution of MySQL database architecture
Idea configuration 360zip open by default -- external tools
三年进账35.31亿,这个江西老表要IPO了
The three-year revenue is 3.531 billion, and this Jiangxi old watch is going to IPO
ctf-pikachu-CSRF
leetcode刷题:二叉树04(二叉树的层序遍历)
拼夕夕二面:说说布隆过滤器与布谷鸟过滤器?应用场景?我懵了。。
软件测试是干什么的 发现缺陷错误,提高软件的质量
(指針)自己寫一個比較字符串大小的函數,功能與strcmp類似。
Cesiumjs 2022^ source code interpretation [0] - article directory and source code engineering structure