springCloud learning portal (xiv): Hystrix View fallback reason

1, the new UserFeignClientFallbackFactory class that implements the interface FallbackFactory, rewrite create interfaces:

@Component
public class UserFeignClientFallackFactory implements FallbackFactory<UserFeignClient> {

    private static final Logger LOGGER = LoggerFactory.getLogger(UserFeignClientFallackFactory.class);

    @Override
    public UserFeignClient create(Throwable throwable) {
        return new UserFeignClient() {
            @Override
            public Map findById(Integer userId) {

                UserFeignClientFallackFactory.LOGGER.info("===================fallback;reason was:",throwable);

                Map<String, String> user = new HashMap<>(3);
                user.put ( "name", "default user");
                user.put("id","-1");
                user.put("age","18");
                return user;

            }
        };
    }
}

2, modify FeignClient categories:

@FeignClient(name = "user",fallbackFactory = UserFeignClientFallackFactory.class)
public interface UserFeignClient {
    @RequestMapping(value = "/user/getUserInfo", method = RequestMethod.GET)
    Map findById(@RequestParam("userId") Integer userId);
}

Use @FeignClient of fallbackFactory property is set fallback logic.

3, the same test results.




Guess you like

Origin blog.51cto.com/13593129/2470881