openFeignを使用して負荷分散を実現します

1.依存関係を導入する

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

2.他のマイクロサービスインターフェイスを作成して呼び出す

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

3.このアノテーションをメインのスタートアップクラスに追加します

@EnableFeignClients

4.制御層を呼び出します


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

おすすめ

転載: blog.csdn.net/qq_45432665/article/details/113893046