谷歌发布/订阅客户端内部java web servlet中的高延迟

时间:2017-05-30 21:38:51

标签: java google-app-engine servlets google-cloud-platform google-cloud-pubsub

我尝试使用此示例Github来使用Google pub / sub java示例在app-engine servlet中推送消息,但是当我的服务器过载时,我的日志显示延迟最多11秒。

关于这个问题的任何想法?

public class SendMessageServlet extends HttpServlet {

@Override
public final void doPost(final HttpServletRequest req,
                         final HttpServletResponse resp)
        throws IOException {
    Pubsub client = PubsubUtils.getClient();
    String message = req.getParameter("message");
    if (!"".equals(message)) {
        String fullTopicName = String.format("projects/%s/topics/%s",
                PubsubUtils.getProjectId(),
                PubsubUtils.getAppTopicName());
        PubsubMessage pubsubMessage = new PubsubMessage();
        pubsubMessage.encodeData(message.getBytes("UTF-8"));
        PublishRequest publishRequest = new PublishRequest();
        publishRequest.setMessages(ImmutableList.of(pubsubMessage));

        client.projects().topics()
                .publish(fullTopicName, publishRequest)
                .execute();
    }
    resp.setStatus(HttpServletResponse.SC_NO_CONTENT);
    resp.getWriter().close();
}

}

0 个答案:

没有答案