use of com.rabbitmq.client.ConnectionFactory in project rabbitmq-java-client by rabbitmq.
the class SslContextFactoryTest method doTestSetSslContextFactory.
private void doTestSetSslContextFactory(Supplier<ConnectionFactory> supplier) throws Exception {
ConnectionFactory connectionFactory = supplier.get();
SslContextFactory sslContextFactory = sslContextFactory();
connectionFactory.setSslContextFactory(sslContextFactory);
Connection connection = connectionFactory.newConnection("connection01");
TestUtils.close(connection);
try {
connectionFactory.newConnection("connection02");
fail("The SSL context of this client should not trust the server");
} catch (SSLHandshakeException e) {
// OK
}
}
use of com.rabbitmq.client.ConnectionFactory in project rabbitmq-java-client by rabbitmq.
the class TrafficListenerTest method trafficListenerIsCalled.
@Test
public void trafficListenerIsCalled() throws Exception {
ConnectionFactory cf = TestUtils.connectionFactory();
TestTrafficListener testTrafficListener = new TestTrafficListener();
cf.setTrafficListener(testTrafficListener);
configurator.accept(cf);
try (Connection c = cf.newConnection()) {
Channel ch = c.createChannel();
String queue = ch.queueDeclare().getQueue();
CountDownLatch latch = new CountDownLatch(1);
ch.basicConsume(queue, true, (consumerTag, message) -> latch.countDown(), consumerTag -> {
});
String messageContent = UUID.randomUUID().toString();
ch.basicPublish("", queue, null, messageContent.getBytes());
assertTrue(latch.await(5, TimeUnit.SECONDS));
assertEquals(1, testTrafficListener.outboundContent.size());
assertEquals(messageContent, testTrafficListener.outboundContent.get(0));
assertEquals(1, testTrafficListener.inboundContent.size());
assertEquals(messageContent, testTrafficListener.inboundContent.get(0));
}
}
use of com.rabbitmq.client.ConnectionFactory in project rabbitmq-java-client by rabbitmq.
the class CloseInMainLoop method specialConnectionFactory.
private ConnectionFactory specialConnectionFactory() {
ConnectionFactory f = TestUtils.connectionFactory();
f.setExceptionHandler(new DefaultExceptionHandler() {
@Override
public void handleConsumerException(Channel channel, Throwable exception, Consumer consumer, String consumerTag, String methodName) {
try {
// TODO: change this to call 4-parameter close and make 6-parm one private
((AMQConnection) channel.getConnection()).close(AMQP.INTERNAL_ERROR, "Internal error in Consumer " + consumerTag, false, exception, -1, false);
} catch (Throwable e) {
// Man, this clearly isn't our day.
// TODO: Log the nested failure
} finally {
closeLatch.countDown();
}
}
});
return f;
}
use of com.rabbitmq.client.ConnectionFactory in project rabbitmq-java-client by rabbitmq.
the class DnsRecordIpAddressResolverTests method loopbackInterfaceResolution.
@Test
public void loopbackInterfaceResolution() throws IOException, TimeoutException {
DnsRecordIpAddressResolver addressResolver = new DnsRecordIpAddressResolver("127.0.0.1");
ConnectionFactory connectionFactory = newConnectionFactory();
Connection connection = connectionFactory.newConnection(addressResolver);
try {
connection.createChannel();
} finally {
connection.abort();
}
}
use of com.rabbitmq.client.ConnectionFactory in project rabbitmq-java-client by rabbitmq.
the class AmqpUriTest method processUriQueryParameterShouldBeCalledForNotHandledParameter.
@Test
public void processUriQueryParameterShouldBeCalledForNotHandledParameter() throws Exception {
Map<String, String> processedParameters = new HashMap<>();
ConnectionFactory cf = new ConnectionFactory() {
@Override
protected void processUriQueryParameter(String key, String value) {
processedParameters.put(key, value);
}
};
cf.setUri("amqp://user:pass@host:10000/vhost?heartbeat=60&key=value");
assertThat(processedParameters).hasSize(1).containsEntry("key", "value");
}
Aggregations