在JSP當我到了「QueueingConsumer.Delivery快遞= consumer.nextDelivery()」的頁面卡住加載。該消息被消耗,但jsp不會加載,也不會產生錯誤。請幫助JSP的RabbitMQ:如何消費一條消息
String QUEUE_NAME = "hello";
ConnectionFactory factory = new ConnectionFactory();
factory.setHost("localhost");
Connection connection = factory.newConnection();
Channel channel = connection.createChannel();
channel.queueDeclare(QUEUE_NAME, false, false, false, null);
out.println(" [*] Waiting for messages. To exit press CTRL+C");
QueueingConsumer consumer = new QueueingConsumer(channel);
channel.basicConsume(QUEUE_NAME, true, consumer);
while (true) {
QueueingConsumer.Delivery delivery = consumer.nextDelivery();
String message = new String(delivery.getBody());
out.println(" [x] Received '" + message + "'");
}
我看不到出路,雖然循環? – fvu
正如fvu所指出的那樣,即使沒有while循環,頁面仍然停留在QueueingConsumer.Delivery delivery = consumer.nextDelivery()上,請求的處理將停留在while循環 –
中。 –