KafkaReciveFallbackFactory.java 1.1 KB
package com.tianbo.messagebus.myinterface;

import com.tianbo.messagebus.controller.response.ResultJson;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

@Component
@Slf4j
public class KafkaReciveFallbackFactory implements FallbackFactory<KafkaReciveApi> {

    @Override
    public KafkaReciveApi create(Throwable cause) {
        log.error("获取消费者消息接口调用出错",cause);
        return new KafkaReciveApi() {
            @Override
            public ResultJson<List<String>> recive(String username) {
                log.info("[FEGIN-ERR]获取消息失败");
                return new ResultJson<>("400","获取消息失败",new ArrayList<>());
            }

            @Override
            public ResultJson<List<String>> getMessages(String username) {
                log.info("[FEGIN-ERR]获取消息失败");
                return new ResultJson<>("400","获取消息失败",new ArrayList<>());
            }
        };
    }
}