App Engine> 60秒后端处理? [英] App Engine >60 seconds backend processing?

查看:105
本文介绍了App Engine> 60秒后端处理?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个接收pubsub消息的appengine应用程序。

I have an appengine app which receives pubsub messages.

我正在处理可能需要60秒以上的数据。

I am processing the data which might take more than 60 seconds.

由于请求处理程序是 limited 持续60秒,我马上承认酒吧,然后进行处理。

Since the request handler is limited for 60 seconds, I acknowledge the pubsub straight away and then do the processing.

虽然这没有帮助 - 即使处理完成,我发送的信息也一次又一次地重试(我在记录器中看到)。

Though this does not help - the messages I send are retried again and again (I see in the logger) even though the processing was done.

这是我的代码:

public class Handler extends HttpServlet {


@Override
public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException  {


    // Acknowledge the message by returning a success code
    resp.setStatus(HttpServletResponse.SC_OK);
    resp.getWriter().close();

    JsonParser parser = JacksonFactory.getDefaultInstance().createJsonParser(req.getInputStream());
    parser.skipToKey("message");

    PubsubMessage message = parser.parseAndClose(PubsubMessage.class);
    log.info("request was received " +  message.getMessageId());
    String payload = new String(message.decodeData(), "UTF-8");

    doSomthingWithPayload(payload); // this takes more than 60 seconds
}

}

我尝试使用任务队列,但由于我的数据非常大,所以我得到任务大小太大

I tried using task queue, but since my data is very large I get Task size too large

问题:

questions:


  1. 这是确认pubsub的正确方法吗?

  2. 过程可能需要超过60几秒后确认?


    • 如果是 - 为什么我的pubsub消息一次又一次地重新发送?
    • 如果不是这样:
    • 一个解决办法 - 虽然我不能使用任务队列?

  1. is this the right way to acknowledge the pubsub?
  2. can the process take more than 60 seconds after acknowledging?
    • if yes - why is my pubsub message resent again and again?
    • if not: what can I do as a work around - while I cannot use task queue?


推荐答案

servlet线程尽快完成。在你的代码中,你编写响应,而不是在servlet线程上做有效负载处理。在收到请求之后,您应立即解析并将有效内容存储到数据存储,启动异步处理(通过任务队列),设置状态HttpServletResponse.SC_OK并从 doPost 返回。如果您将使用数据存储来存储您的有效负载,您将不会达到任务大小限制,因为您只能将任务放入任务数据存储记录标识,而不是所有有效负载。

You need to let your servlet thread go ASAP. In your code you writing response and than doing payload processing on servlet thread. Instead immediately after you received request you should parse and store payload to datastore, initiate async processing (via task queue), set status HttpServletResponse.SC_OK and return from doPost. If you will use datastore to store your payload you will not hit task size limit because you will be able to put in task only datastore record ID, not all payload.

这篇关于App Engine> 60秒后端处理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆