当前位置: 首页>编程语言>正文

dubbo代码层服务降级---mock

@DubboReference(loadbalance = LoadbalanceRules.CONSISTENT_HASH
        ,group = "dev",version = "1.0",mock ="com.lvym.dubbo.mock.FinanceMock")
private FinanceRemoteService financeRemoteService;

@Override
public Object getFinance() {

    String s = financeRemoteService.sayHello();
    System.out.println(s);
    //return financeRemoteService.getPort();
    return s;
}
package com.lvym.dubbo.mock;

import com.lvym.dubbo.FinanceRemoteService;
import com.lvym.model.dto.finance.TradeDTO;
import com.lvym.model.po.finance.TradeLogPO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


import java.util.Collections;
import java.util.List;

public class FinanceMock implements FinanceRemoteService {

    private final Logger logger= LoggerFactory.getLogger(getClass());

    @Override
    public String getPort() {
        return "";
    }

    @Override
    public List<TradeLogPO> listTradeLog(TradeDTO tradeDTO) {
        return Collections.emptyList();
    }

    @Override
    public String sayHello() {
      logger.info(">>>>>我是MOCK>>>>>>>>>>>>");
        return "我是FinanceMOCK!!!";
    }


}

https://www.xamrdz.com/lan/5k41963269.html

相关文章: