简体   繁体   中英

Spring batch writer throttling

I working spring batch project, to read records from the DB then write to rabbitmq, then send to HTTP message gateway. The gateway has 150TPS and I need to limit my application to 150TPS. Is there a way to throttle with spring batch or any other better way?

You can do it:

  • On Spring Batch side: using a ItemWriteListener#beforeWrite , delay the writing of items using Thread.sleep or using a rate limiting library like Guava or Resilience4j
  • On RabbitMQ side: using the delayed-message-plugin to delay the delivery of messages at the desired rate.

Hope this helps.

You can try it with chunk oriented processing by defining the maximum chunk size to your TPS or less than that.

You can refer to the below doc for implementing Spring batch by Chunk Oriented Processing:

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

Hope it helps...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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