I try this example Github to use Google pub/sub java example to push messages inside app-engine servlet, however my logs shows latency up to 11 seconds when my servers are overloaded.
Any idea about this issue?
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();
}
}