안녕하세요. 오랫동안 Tomcat에서 혜성을 사용하여 채팅 응용 프로그램을 만들고 있습니다. 문제는 열려있는 연결을 위해 30 초 동안 제한이있는 클라우드에 응용 프로그램을 배포했다는 것입니다. 그래서 서버가 응답하기 위해 30 초 이상 걸릴 때마다 (예 : 채팅 메시지가 푸시되지 않은 경우처럼) 클라이언트는 504 예외를 수신합니다.혜성과 타임 아웃
그래서 혜성 기술은 시간 제한이있는 시나리오에서 작동하지 않습니다.
코드 조각
package com.cumulations.clique.ChatHandler;
public class AsynchronousGetChatHandler extends HttpServlet implements
CometProcessor {
public static HashMap consumerConnectionQueue = new HashMap();
public static HashMap consumerPoolingQueue = new HashMap<String, String>();
public static HashMap consumerSessionQueue = new HashMap<String, Date>();
public static ConnectionFactory factory;
public static Connection connection;
public void event(CometEvent event) throws IOException, ServletException {
HttpServletRequest request = event.getHttpServletRequest();
HttpServletResponse response = event.getHttpServletResponse();
String userName = request.getParameter("userName");
String sessionId = request.getParameter("accesskey");
AsynchronousGetChatHandler.consumerPoolingQueue.put(userName, "ON");
try {
if (event.getEventType() == CometEvent.EventType.BEGIN) {
String str = fromRabitQ(userName);
if (str != null) {
System.out.println("delivering a message: " + str);
PrintWriter writer = response.getWriter();
writer.println(str);
writer.flush();
writer.close();
}
else {
PrintWriter writer = response.getWriter();
writer.println("");
writer.flush();
writer.close();
}
}
}
catch (Exception e) {
throw new ServletException("Recieving exception");
// TODO: handle exception
}
}
public static String fromRabitQ(String userName) throws Exception {
try {
Channel channel;
QueueingConsumer consumer;
String QUEUE_NAME = userName;
String message = "";
connection = RabbitMqConnection.getConnection();
channel = connection.createChannel();
channel.queueDeclare(QUEUE_NAME, true, false, false, null);
consumer = new QueueingConsumer(channel);
channel.basicConsume(QUEUE_NAME, true, consumer);
QueueingConsumer.Delivery delivery;
delivery = consumer.nextDelivery(27000);
if (delivery != null) {
message = new String(delivery.getBody());
} else {
message = null;
}
channel.basicCancel(consumer.getConsumerTag());
channel.close();
return message;
}
catch (Exception e) {
System.out.println("Exception occured while receiveing " + e);
throw e;
}
}
}를 부착
이 응답을 참조하십시오 : http://stackoverflow.com/questions/11430841/what-is-the-best-way-to-automatically-reestablish-long-polling-request/11441711#11441711 –
감사합니다. alessandro .. 전 (실제로 나는 rabbitMq에서 28 초 동안 메시지를 기다리고 비어있는 응답을 반환합니다.) 30 초를 기다린 후 빈 응답을 보냈습니다. 그러나 내가 jMeter에서로드를 시도했을 때 504 요청을 반환하는 많은 것을 볼 수있었습니다. 504 로그 때문에 항목의 크기가 커졌습니다. 적어도 504 로깅을 피하는 방법이 있습니까? –
28 초보다 짧은 창을 사용해 보셨습니까? 아마 20 초? 도움이되지 않는다면 JMeter로 부하를 재현하는 방법과 함께 소스를 애플리케이션에 게시하여 추가 문제를 해결할 수 있습니까? –