【问题标题】:Spring Boot - introduce wait time when processing request bodySpring Boot - 处理请求体时引入等待时间
【发布时间】:2019-03-07 17:06:57
【问题描述】:

我有一个带有 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
    } }

【问题讨论】:

  • 如果对您有用,请查看此链接stackoverflow.com/questions/46177268/…
  • 为什么需要这个?如果你想在生产中使用它,你可以简单地添加一个过滤器,比如@Cyril Beslay 回答。您需要它进行测试吗?

标签: java spring spring-boot jetty


【解决方案1】:

您可以定义一个过滤器 (https://www.baeldung.com/spring-boot-add-filter) 来执行 Thread.sleep()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-02-23
    • 1970-01-01
    • 2012-11-07
    • 2011-11-01
    • 1970-01-01
    • 2022-11-28
    • 2019-11-01
    相关资源
    最近更新 更多