forked from rongchao/epmet-cloud-rizhao
				
			
				 3 changed files with 49 additions and 0 deletions
			
			
		@ -0,0 +1,24 @@ | 
				
			|||
package com.epmet.controller; | 
				
			|||
 | 
				
			|||
import com.epmet.commons.tools.utils.Result; | 
				
			|||
import com.epmet.feign.LbFeignClient; | 
				
			|||
import org.springframework.beans.factory.annotation.Autowired; | 
				
			|||
import org.springframework.web.bind.annotation.PostMapping; | 
				
			|||
import org.springframework.web.bind.annotation.RequestMapping; | 
				
			|||
import org.springframework.web.bind.annotation.RestController; | 
				
			|||
 | 
				
			|||
import javax.servlet.http.HttpServletRequest; | 
				
			|||
 | 
				
			|||
@RestController | 
				
			|||
@RequestMapping("lbtest") | 
				
			|||
public class LbTestController { | 
				
			|||
 | 
				
			|||
    @Autowired | 
				
			|||
    private LbFeignClient lbFeignClient; | 
				
			|||
 | 
				
			|||
    @PostMapping("get-host") | 
				
			|||
    public Result getHost() { | 
				
			|||
        Result host = lbFeignClient.getHost(); | 
				
			|||
        return host; | 
				
			|||
    } | 
				
			|||
} | 
				
			|||
@ -0,0 +1,12 @@ | 
				
			|||
package com.epmet.feign; | 
				
			|||
 | 
				
			|||
import com.epmet.commons.tools.utils.Result; | 
				
			|||
import com.epmet.feign.fallback.LbFeignClientFallback; | 
				
			|||
import org.springframework.cloud.openfeign.FeignClient; | 
				
			|||
import org.springframework.web.bind.annotation.PostMapping; | 
				
			|||
 | 
				
			|||
@FeignClient(name = "gov-voice-server", fallback = LbFeignClientFallback.class) | 
				
			|||
public interface LbFeignClient { | 
				
			|||
    @PostMapping("/gov/voice/lb/get-host") | 
				
			|||
    Result getHost(); | 
				
			|||
} | 
				
			|||
@ -0,0 +1,13 @@ | 
				
			|||
package com.epmet.feign.fallback; | 
				
			|||
 | 
				
			|||
import com.epmet.commons.tools.utils.Result; | 
				
			|||
import com.epmet.feign.LbFeignClient; | 
				
			|||
import org.springframework.stereotype.Component; | 
				
			|||
 | 
				
			|||
@Component | 
				
			|||
public class LbFeignClientFallback implements LbFeignClient { | 
				
			|||
    @Override | 
				
			|||
    public Result getHost() { | 
				
			|||
        return new Result().error(0, "请求失败"); | 
				
			|||
    } | 
				
			|||
} | 
				
			|||
					Loading…
					
					
				
		Reference in new issue