简体   繁体   English

播放忽略继续 100 个请求

[英]Play ignore continue 100 requests

A play Controller with Actions for POST requests, may need to ignore HTTP Request Automatic Retries to prevent Controller code being ran multiple times. A play Controller 与 POST 请求的操作,可能需要忽略HTTP 请求自动重试以防止 Controller 代码运行多次。

What is the best way to do this in Play?在 Play 中执行此操作的最佳方法是什么?

I would recommend the following:我会推荐以下内容:

  1. add a unique ID to every post request as part of the query string.将唯一 ID 作为查询字符串的一部分添加到每个发布请求。

  2. Extend the DefaultHttpRequestHandler , as explained here扩展DefaultHttpRequestHandler ,如此所述

  3. In your extension check if this is a request for which you want to prevent retries and read the request's ID using getQueryString on the RequestHeader , see docs here .在您的扩展程序中检查这是否是您想要阻止重试的请求并使用RequestHeader上的getQueryString读取请求的 ID,请参阅此处的文档。

  4. Check if you have already seen the ID by querying a datastore such as Redis.通过查询 Redis 等数据存储来检查您是否已经看到了 ID。 Save the ID to Redis if this is the first time you have seen it.如果这是您第一次看到它,请将 ID 保存到 Redis。

  5. Drop the POST request if you have already seen the ID, otherwise forward it to the router.如果您已经看到 ID,则丢弃 POST 请求,否则将其转发到路由器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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