当前位置:网站首页>[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);
}
边栏推荐
- 北漂程序员,月薪20K,一年攒15W,正常吗?
- What does software testing do? Find defects and improve the quality of software
- Katalon framework test web (XXVI) automatic email
- [Huawei cloud IOT] reading notes, "Internet of things: core technology and security of the Internet of things", Chapter 3 (I)
- RHCSA 01 - 创建分区与文件系统
- Leetcode skimming: binary tree 08 (maximum depth of n-ary tree)
- Pointer array and array pointer
- TCP-三次握手和四次挥手简单理解
- Redis cluster uses Lua script. Lua script can also be used for different slots
- Interpretation of leveldb source code skiplist
猜你喜欢

I Build a simple microservice project

Flink学习8:数据的一致性

Redis:有序集合zset类型数据操作命令

leetcode刷题:二叉树05(翻转二叉树)

Confession code collection, who says program apes don't understand romance
![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

Balance between picture performance of unity mobile game performance optimization spectrum and GPU pressure

Leetcode skimming: binary tree 09 (minimum depth of binary tree)

统计遗传学:第三章,群体遗传

There is a problem that the package cannot be parsed in the like project
随机推荐
How was my life in 2021
量子力学习题
Storage of MySQL database
ctf-pikachu-XSS
Pytest multi process / multi thread execution test case
三年进账35.31亿,这个江西老表要IPO了
01 QEMU starts the compiled image vfs: unable to mount root FS on unknown block (0,0)
Idea modify body color
SDP中的SPA
ctf-pikachu-XSS
Balance between picture performance of unity mobile game performance optimization spectrum and GPU pressure
[webrtc] M98 Ninja build and compile instructions
思考的小记录
[book club issue 13] multimedia processing tool ffmpeg tool set
[microservice openfeign] @feignclient detailed explanation
Evolution of MySQL database architecture
How to add custom API objects in kubernetes (1)
Huawei cloud Kunpeng engineer training (Guangxi University)
Activiti7 task service - process variables (setvariable and setvariablelocal)
毕业三年,远程半年 | 社区征文