use of com.rabbitmq.client.ConnectionFactory in project rabbitmq-java-client by rabbitmq.
the class TopologyRecoveryRetry method newConnectionFactory.
@Override
protected ConnectionFactory newConnectionFactory() {
ConnectionFactory connectionFactory = TestUtils.connectionFactory();
connectionFactory.setTopologyRecoveryRetryHandler(RETRY_ON_QUEUE_NOT_FOUND_RETRY_HANDLER.backoffPolicy(attempt -> backoffConsumer.accept(attempt)).build());
connectionFactory.setNetworkRecoveryInterval(1000);
return connectionFactory;
}
use of com.rabbitmq.client.ConnectionFactory in project rabbitmq-java-client by rabbitmq.
the class ExceptionHandling method nullExceptionHandler.
@Test
public void nullExceptionHandler() {
ConnectionFactory cf = TestUtils.connectionFactory();
try {
cf.setExceptionHandler(null);
fail("expected setExceptionHandler to throw");
} catch (IllegalArgumentException iae) {
// expected
}
}
use of com.rabbitmq.client.ConnectionFactory in project rabbitmq-java-client by rabbitmq.
the class ExceptionHandling method testConsumerHandleConsumerException.
protected void testConsumerHandleConsumerException(ExceptionHandler eh, CountDownLatch latch, boolean expectChannelClose) throws InterruptedException, TimeoutException, IOException {
ConnectionFactory cf = newConnectionFactory(eh);
assertEquals(cf.getExceptionHandler(), eh);
Connection conn = cf.newConnection();
assertEquals(conn.getExceptionHandler(), eh);
Channel ch = conn.createChannel();
String q = ch.queueDeclare().getQueue();
ch.basicConsume(q, new DefaultConsumer(ch) {
@Override
public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
throw new RuntimeException("exception expected here, don't freak out");
}
});
ch.basicPublish("", q, null, "".getBytes());
wait(latch);
assertEquals(!expectChannelClose, ch.isOpen());
}
use of com.rabbitmq.client.ConnectionFactory in project rabbitmq-java-client by rabbitmq.
the class BlockedConnection method connection.
private Connection connection(final CountDownLatch latch) throws IOException, TimeoutException {
ConnectionFactory factory = TestUtils.connectionFactory();
Connection connection = factory.newConnection();
connection.addBlockedListener(new BlockedListener() {
public void handleBlocked(String reason) throws IOException {
try {
unblock();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
public void handleUnblocked() throws IOException {
latch.countDown();
}
});
return connection;
}
use of com.rabbitmq.client.ConnectionFactory in project rabbitmq-java-client by rabbitmq.
the class ChannelLimitNegotiation method openingTooManyChannels.
@Test
public void openingTooManyChannels() throws Exception {
int n = 48;
Connection conn = null;
try {
Host.rabbitmqctl("eval 'application:set_env(rabbit, channel_max, " + n + ").'");
ConnectionFactory cf = TestUtils.connectionFactory();
conn = cf.newConnection();
assertEquals(n, conn.getChannelMax());
for (int i = 1; i <= n; i++) {
assertNotNull(conn.createChannel(i));
}
// ChannelManager guards against channel.open being sent
assertNull(conn.createChannel(n + 1));
// Construct a channel directly
final ChannelN ch = new ChannelN(((AutorecoveringConnection) conn).getDelegate(), n + 1, new ConsumerWorkService(Executors.newSingleThreadExecutor(), Executors.defaultThreadFactory(), ConnectionFactory.DEFAULT_SHUTDOWN_TIMEOUT));
conn.addShutdownListener(new ShutdownListener() {
public void shutdownCompleted(ShutdownSignalException cause) {
// make sure channel.open continuation is released
ch.processShutdownSignal(cause, true, true);
}
});
ch.open();
fail("expected channel.open to cause a connection exception");
} catch (IOException e) {
checkShutdownSignal(530, e);
} finally {
TestUtils.abort(conn);
Host.rabbitmqctl("eval 'application:set_env(rabbit, channel_max, 0).'");
}
}
Aggregations