Spring Boot - 在处理请求体时引入等待时间

问题描述 投票:1回答:1

我有一个带Jetty的Spring Boot应用程序,它接受传入的请求。是否存在任何类型的Spring Boot内置机制,可以在处理每条消息之间添加延迟(等待1秒,进程1消息,等待1秒,进程1消息...无批量处理),例如1秒而不是TimeUnit.SECONDS.sleep(1),更不用说这里是否安全。谢谢。

@RestController 
public class NotificationController {

    @RequestMapping(
            method = RequestMethod.POST,
            consumes = MediaType.TEXT_XML_VALUE)
    @ResponseStatus(value = HttpStatus.OK)
    public void notification(@RequestBody String payload) {
       // handle payload here
    } }
java spring spring-boot jetty
1个回答
2
投票

你可以定义一个执行Thread.sleep()的Filter(https://www.baeldung.com/spring-boot-add-filter

© www.soinside.com 2019 - 2024. All rights reserved.