use of com.rabbitmq.client.DefaultConsumer in project rabbitmq-java-client by rabbitmq.
the class CloseInMainLoop method closeWithFaultyConsumer.
// The thrown runtime exception should get intercepted by the
// consumer exception handler, and result in a clean shut down.
@Test
public void closeWithFaultyConsumer() throws Exception {
SpecialConnection connection = new SpecialConnection();
Channel channel = connection.createChannel();
channel.exchangeDeclare("x", "direct");
channel.queueDeclare("q", false, false, false, null);
channel.queueBind("q", "x", "k");
channel.basicConsume("q", true, new DefaultConsumer(channel) {
@Override
public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) {
throw new RuntimeException("I am a bad consumer");
}
});
channel.basicPublish("x", "k", null, new byte[10]);
assertTrue(closeLatch.await(1000, TimeUnit.MILLISECONDS));
assertTrue(connection.hadValidShutdown());
}
use of com.rabbitmq.client.DefaultConsumer in project rabbitmq-java-client by rabbitmq.
the class Confirm method basicRejectRequeue.
@Test
public void basicRejectRequeue() throws IOException, InterruptedException, TimeoutException {
basicRejectCommon(true);
/* wait confirms to go through the broker */
Thread.sleep(1000);
channel.basicConsume("confirm-test-noconsumer", true, new DefaultConsumer(channel));
channel.waitForConfirmsOrDie(60000);
}
use of com.rabbitmq.client.DefaultConsumer in project rabbitmq-java-client by rabbitmq.
the class Confirm method basicRecover.
@Test
public void basicRecover() throws IOException, InterruptedException, TimeoutException {
publishN("", "confirm-test-noconsumer", true, false);
for (long i = 0; i < NUM_MESSAGES; i++) {
GetResponse resp = channel.basicGet("confirm-test-noconsumer", false);
resp.getEnvelope().getDeliveryTag();
// not acking
}
channel.basicRecover(true);
Thread.sleep(1000);
channel.basicConsume("confirm-test-noconsumer", true, new DefaultConsumer(channel));
channel.waitForConfirmsOrDie(60000);
}
use of com.rabbitmq.client.DefaultConsumer in project rabbitmq-java-client by rabbitmq.
the class ConsumerPriorities method assertFailValidation.
private void assertFailValidation(Map<String, Object> args) throws IOException {
Channel ch = connection.createChannel();
String queue = ch.queueDeclare().getQueue();
try {
ch.basicConsume(queue, true, args, new DefaultConsumer(ch));
fail("Validation should fail for " + args);
} catch (IOException ioe) {
checkShutdownSignal(AMQP.PRECONDITION_FAILED, ioe);
}
}
use of com.rabbitmq.client.DefaultConsumer in project rabbitmq-java-client by rabbitmq.
the class QueueLease method expiresWithConsumers.
@Test
public void expiresWithConsumers() throws InterruptedException, IOException {
Map<String, Object> args = new HashMap<String, Object>();
args.put("x-expires", QUEUE_EXPIRES);
channel.queueDeclare(TEST_EXPIRE_QUEUE, false, false, false, args);
Consumer consumer = new DefaultConsumer(channel);
String consumerTag = channel.basicConsume(TEST_EXPIRE_QUEUE, consumer);
Thread.sleep(SHOULD_EXPIRE_WITHIN);
try {
channel.queueDeclarePassive(TEST_EXPIRE_QUEUE);
} catch (IOException e) {
checkShutdownSignal(AMQP.NOT_FOUND, e);
fail("Queue expired before before passive re-declaration.");
}
channel.basicCancel(consumerTag);
Thread.sleep(SHOULD_EXPIRE_WITHIN);
try {
channel.queueDeclarePassive(TEST_EXPIRE_QUEUE);
fail("Queue should have been expired by now.");
} catch (IOException e) {
checkShutdownSignal(AMQP.NOT_FOUND, e);
}
}
Aggregations