我尝试使用此示例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();
}
}