Use openFeign para obter balanceamento de carga

1. Introduzir dependências

  <!--openfeign-->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-openfeign</artifactId>
        </dependency>

2. Escreva e chame outras interfaces de microsserviço

@Component
@FeignClient(value = "CLOUD-PAYMENT-SERVICE") //这是注册到eureka微服务的名称
public interface PaymentFeignService {
    
    
    @GetMapping(value = "/get")//这是调用的微服务的地址
    public CommonResult<Payment> getById(@RequestParam("id") int id);
}

3. Adicione esta anotação à classe de inicialização principal

@EnableFeignClients

4. Chame a camada de controle


    @Resource
    private PaymentFeignService paymentFeignService;
    
    @GetMapping(value = "/consumer/payment/get")
    public CommonResult<Payment> getById(@RequestParam("id") int id){
    
    
        return paymentFeignService.getById(id);
    }

Acho que você gosta

Origin blog.csdn.net/qq_45432665/article/details/113893046
Recomendado
Clasificación