【发布时间】:2021-01-12 00:36:01
【问题描述】:
我有带有 spring MVC 的 spring 批处理应用程序。在这个应用程序中,我必须调用 Google API。 API 有每秒最多 4 个请求的限制。现在我必须从 Spring Batch 中调用 google API。所以我有两个问题。
q1:如何实现对 Google API 的休息调用。我知道 Rest Template,但我希望有更好的方法,比如我们在微服务中使用的 feign 客户端。
q2:如何限制每秒 4 个调用。
如果您有任何问题。请告诉我
【问题讨论】:
-
如果每秒有 5 次调用,您希望发生什么?放弃第 5 次通话(例如返回错误)或再等一秒钟,这样您就不再受到速率限制?您可能对这样的事情感兴趣:stackoverflow.com/questions/31883739/…
-
您需要使用什么 Google API?
-
实际上,我在春季批次中使用了这个逻辑,我对 Google API 有连续 15K 的点击。但是 API 每秒有 4 个请求的限制,所以我不想对 Google API 造成更多影响,因为可能存在一些成本问题。
-
@TomVanRossom maps.googleapis.com
标签: spring spring-boot spring-batch spring-restcontroller