[英]How to handle large response from external api in Spring Boot application
In our spring boot application, we are calling the external API for some purpose, it is returning around 20mb JSON data as the response. 在我们的Spring Boot应用程序中,出于某种目的,我们正在调用外部API,它会返回大约20mb的 JSON数据作为响应。 After receiving the response, using ObjectMapper we are mapping the response to a POJO. 收到响应后,使用ObjectMapper将响应映射到POJO。
We are using RestTemplate to call the API and receive the response. 我们正在使用RestTemplate来调用API并接收响应。
What are the best practices to handle large response data without getting memory issues in Spring boot application? 在Spring Boot应用程序中处理大型响应数据而又不会出现内存问题的最佳实践是什么?
Thanks 谢谢
I would say there are two good approaches: 我会说有两种好的方法:
But having said that: when your requirement is really to return all that data with one call, then there isn't too much you can do. 但要说的是:当您的要求实际上是一次调用就返回所有数据时,您将无能为力。 You might consider to not use object mapping for the complete response then. 您可能会考虑不要将对象映射用于完整的响应。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.