feign遠程調用
feign遠程調用:
package com.reachauto.vsp.portal;
import com.reachauto.vsp.portal.service.DictCacheService;
import javax.annotation.Resource;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.openfeign.EnableFeignClients;
//@ServletComponentScan
@EnableFeignClients(basePackages = {"com.reachauto.vsp.portal.feign", "com.reachauto.vspcloud.feign"})
@SpringBootApplication(scanBasePackages = {"com.reachauto.vspcloud", "com.reachauto.vsp.portal"})
@MapperScan({
"com.reachauto.vspcloud.vsptrunk.database.mapper",
"com.reachauto.vsp.portal.mapper",
})
public class PortalApplication implements CommandLineRunner {
@Resource
private DictCacheService dictCacheService;
public static void main(String[] args) {
SpringApplication.run(PortalApplication.class, args);
}
@Override
public void run(String... args) {
dictCacheService.refreshDictCache();
}
}
package com.reachauto.vsp.portal.feign;
import com.reachauto.vsp.portal.bean.param.RechargeablePackageParameter;
import com.reachauto.vsp.portal.bean.vo.FlowPackageVo;
import com.reachauto.vsp.portal.feign.fallback.VspcloudVsptrunkCmccFeignFallback;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import com.reachauto.vspcloud.common.response.Response;
import java.util.List;
/**
* url 本地調試使用localhost:15007/trafficManagement/queryRechargeRecordList etst
*/
// url = "http://localhost:15007",
@FeignClient(name = "vspcloud-vsptrunk-cmcc",url = "http://localhost:15007",fallback = VspcloudVsptrunkCmccFeignFallback.class)
public interface VspcloudVsptrunkCmccFeign {
@RequestMapping(value = "/trafficManagement/getPackageFlow", method = RequestMethod.POST)
Response<List<FlowPackageVo>> getPackageFlow(@RequestBody RechargeablePackageParameter rechargeablePackageParameter);
@RequestMapping(value = "/trafficManagement/queryRechargeRecordList", method = RequestMethod.POST)
Response queryRechargeRecordList();
@RequestMapping(value = "/trafficManagement/batchQueryFlow", method = RequestMethod.POST)
String batchQueryFlow(String simcard);
}
// 充值記錄查詢
/**
* 充值記錄查詢
*/
@ApiOperation(value = "流量查詢", notes = "流量查詢")
@ApiResponses(value = {
@ApiResponse(code = 000000, message = "Successful — 請求已完成"),
@ApiResponse(code = 200010, message = "請求失敗")
})
@RequestMapping(value = "/list", method = RequestMethod.POST)
public Response list(String simcard) {
return vspcloudVsptrunkCmccFeign.queryRechargeRecordList();
}
package com.reachauto.vsp.portal.feign.fallback;
import com.reachauto.vsp.portal.bean.param.RechargeablePackageParameter;
import com.reachauto.vsp.portal.bean.vo.FlowPackageVo;
import com.reachauto.vsp.portal.feign.VspcloudVsptrunkCmccFeign;
import com.reachauto.vspcloud.common.response.Response;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.List;
@Slf4j
@Component
public class VspcloudVsptrunkCmccFeignFallback implements VspcloudVsptrunkCmccFeign {
@Override
public Response<List<FlowPackageVo>> getPackageFlow(RechargeablePackageParameter rechargeablePackageParameter) {
log.error("vspcloud-vsptrunk-cmcc調用被熔斷了");
return null;
}
@Override
public Response queryRechargeRecordList() {
log.error("vspcloud-vsptrunk-cmcc調用被熔斷了");
return null;
}
@Override
public String batchQueryFlow(String simcard) {
log.error("vspcloud-vsptrunk-cmcc batchQueryFlow() 調用被熔斷了");
return null;
}
}