简体   繁体   English

在Spring客户端实现中,有没有更好的方法可以同时调用REST API?

[英]Is there any better way to concurrently call REST API in spring client implementation?

I'm implementing one service which is internally calling some third party rest API to get the data and process over it. 我正在实现一项服务,该服务在内部调用一些第三方rest API以获取数据并对其进行处理。 API call can be N number of times based on different user input data, so it can call the API 100 times or 10000 times as well and each API call takes 1-2 seconds on an average that will increase the total time for overall process. 根据不同的用户输入数据,API调用可以是N次,因此它可以调用API 100次或10000次,平均每个API调用需要1-2秒,这将增加整个过程的总时间。

I want to understand if there's any best way to handle such problem smoothly? 我想了解是否有最佳的方法来顺利处理此类问题? I was planning for concurrent API call about 100 times or 1000 times(thread running using @async spring boot method) but again this number of threads execution speed will depend on the system it is running on. 我正计划并发API调用大约100次或1000次(使用@async spring boot方法运行线程),但是线程的执行速度再次取决于它所运行的系统。

Your reply will be great help, Thanks in advance. 您的回复将为您提供很大的帮助,谢谢。

Give a try to reactor project. 尝试反应堆项目。 It requires some effort if you want to be efficient with it, but the code would be pretty simple and if you use Spring 5/Boot 2 then you could take advantage of NIO Spring Web Client. 如果您想提高效率,就需要付出一些努力,但是代码非常简单,如果您使用Spring 5 / Boot 2,则可以利用NIO Spring Web Client。 Otherwise it will be similar to what you've suggested - run concurrently X API calls 否则,它将与您的建议类似-同时运行X API调用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM