微服务中的呼叫服务

时间:2019-11-11 02:08:32

标签: maven spring-boot microservices

我有一个Maven Spring Boot项目,下面包含许多模块相同的图像: Maven Project Spring Boot

我想使用上面很多模块的服务来创建一个模块。 我使用了FeignClients:

@SpringBootApplication
@EnableFeignClients
public class OutBoundAirApplication {
    public static void main(String[] args) {
        SpringApplication.run(OutBoundAirApplication.class, args);

    }

}

并按如下所示创建Interface客户端:

@Service
@FeignClient(name = "buying-rate-service", url = "http://localhost:8001/buyingrate")
public interface BuyingRateServiceClient {

    @GetMapping("/transaction/{transactionID}")
    public BuyingRate getBuyingRateByTransactionID(@PathVariable("transactionID") String transactionID);

    @PostMapping("/")
    public BuyingRate createBuyingRate(@Valid @RequestBody BuyingRate buyingRate);

    @PutMapping("/")
    public BuyingRate editBuyingRate(@Valid @RequestBody BuyingRate buyingRate);

    @DeleteMapping("/{_id}")
    public void deleteBuyingRate(@PathVariable("_id") ObjectId _id);
}

然后,我在控制器中调用接口:

@GetMapping("/buyingrate/transaction/{transactionID}")
    public BuyingRate getBuyingRateByTransactionID(@PathVariable("transactionID") String transactionID){
        BuyingRate  buyingRate = buyingRateServiceClient.getBuyingRateByTransactionID(transactionID);
        return buyingRate;
    }

但是这种方式只调用单个服务,而我想在控制器中一次调用多个服务。 还有另一种方法可以将许多服务从另一个模块调用到另一个模块。你可以帮帮我吗? 谢谢!

0 个答案:

没有答案