package com.xhpc.common.api.factory;

import com.xhpc.common.api.WebSocketService;
import com.xhpc.common.core.domain.R;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * @author yuyang
 * @date 2021/9/10 15:14
 * @Version 1.0
 */
@Component
public class WebSocketFallbackFactory implements FallbackFactory<WebSocketService> {

    private static final Logger logger = LoggerFactory.getLogger(WebSocketFallbackFactory.class);

    @Override
    public WebSocketService create(Throwable cause){
        logger.error("消息发送调用失败：{}//fallback",cause.getMessage());
        return new WebSocketService() {
            @Override
            public R getMessage(String userId, String message) {
                return R.fail(3886,"消息发送调用失败:" + cause.getMessage());
            }
        };
    }
}
