我有一个带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
} }
你可以定义一个执行Thread.sleep()的Filter(https://www.baeldung.com/spring-boot-add-filter)