List of usage examples for com.rabbitmq.client Channel basicNack
void basicNack(long deliveryTag, boolean multiple, boolean requeue) throws IOException;
From source file:uk.ac.sanger.cgp.wwdocker.messages.Messaging.java
License:Open Source License
public void removeFromStateQueue(String queue, String hostToRemove) throws IOException, InterruptedException { logger.trace(queue.concat(": ").concat(hostToRemove)); Connection connectionRcv = getRmqConn(); Channel channel = connectionRcv.createChannel(); int maxTries = channel.queueDeclare(queue, true, false, false, null).getMessageCount(); logger.trace("Queue : messages\t" + queue + " : " + maxTries); QueueingConsumer consumer = new QueueingConsumer(channel); channel.basicConsume(queue, false, consumer); QueueingConsumer.Delivery delivery = consumer.nextDelivery(200); logger.trace(maxTries);/*from www . ja va2 s. c o m*/ while (delivery != null && maxTries > 0) { // the toString in the middle of this is needed as it is wrapped with another type that can hold 4GB Map<String, Object> headers = delivery.getProperties().getHeaders(); if (headers != null && headers.get("host").toString().equals(hostToRemove)) { logger.trace(headers.get("host").toString().concat(" remove")); channel.basicAck(delivery.getEnvelope().getDeliveryTag(), false); } else { channel.basicNack(delivery.getEnvelope().getDeliveryTag(), false, true); } delivery = consumer.nextDelivery(200); maxTries--; } channel.close(); closeRmqConn(connectionRcv); }