春季批作家节流

时间:2018-10-22 05:51:36

标签: java spring spring-boot spring-integration spring-batch

我在春季批处理项目中工作,从DB中读取记录,然后写入Rabbitmq,然后发送至HTTP消息网关。网关具有 150TPS ,我需要将应用程序限制为150TPS。有什么方法可以节气弹簧或其他更好的方法?

2 个答案:

答案 0 :(得分:3)

您可以做到:

  • 在Spring Batch方面:使用ItemWriteListener#beforeWrite,使用Thread.sleep或使用速率限制库(例如GuavaResilience4j
  • )来延迟项目的写入
  • 在RabbitMQ端:使用delayed-message-plugin延迟所需速率的邮件传递。

希望这会有所帮助。

答案 1 :(得分:0)

您可以通过将最大块大小定义为TPS或小于TPS的最大块大小来尝试面向块的处理。

您可以参考以下文档,了解如何通过Chunk Oriented Processing实现Spring批处理:

https://docs.spring.io/spring-batch/trunk/reference/html/configureStep.html

希望有帮助...