use of com.rabbitmq.client.Address in project spring-cloud-connectors by spring-cloud.
the class RabbitConnectionFactoryCreatorTest method assertConnectorPropertiesMatchHosts.
private void assertConnectorPropertiesMatchHosts(ConnectionFactory connector, List<String> uriStrings) throws Exception {
Address[] addresses = (Address[]) ReflectionTestUtils.getField(connector, "addresses");
assertNotNull(addresses);
assertEquals(uriStrings.size(), addresses.length);
for (int i = 0; i < uriStrings.size(); i++) {
URI uri = new URI(uriStrings.get(i));
assertEquals(uri.getHost(), addresses[i].getHost());
assertEquals(uri.getPort(), addresses[i].getPort());
}
}
use of com.rabbitmq.client.Address in project rabbitmq-java-client by rabbitmq.
the class HostnameVerification method hostnameVerificationSucceeds.
@Test
public void hostnameVerificationSucceeds() throws Exception {
ConnectionFactory connectionFactory = TestUtils.connectionFactory();
connectionFactory.useSslProtocol(sslContext);
customizer.accept(connectionFactory);
try (Connection conn = connectionFactory.newConnection(() -> singletonList(new Address("localhost", ConnectionFactory.DEFAULT_AMQP_OVER_SSL_PORT)))) {
assertTrue(conn.isOpen());
}
}
use of com.rabbitmq.client.Address in project rabbitmq-java-client by rabbitmq.
the class HostnameVerification method hostnameVerificationFailsBecauseCertificateNotIssuedForLoopbackInterface.
@Test(expected = SSLHandshakeException.class)
public void hostnameVerificationFailsBecauseCertificateNotIssuedForLoopbackInterface() throws Exception {
ConnectionFactory connectionFactory = TestUtils.connectionFactory();
connectionFactory.useSslProtocol(sslContext);
customizer.accept(connectionFactory);
connectionFactory.newConnection(() -> singletonList(new Address("127.0.0.1", ConnectionFactory.DEFAULT_AMQP_OVER_SSL_PORT)));
fail("The server certificate isn't issued for 127.0.0.1, the TLS handshake should have failed");
}
use of com.rabbitmq.client.Address in project microservices by pwillhan.
the class RabbitMqMiddlewareModule method channelProvider.
@LazySingleton
@Provides
public ChannelProvider channelProvider(final ServiceConfiguration configuration) throws URISyntaxException, IOException, NoSuchAlgorithmException, KeyManagementException {
final RabbitMqConfiguration rabbitMqConfiguration = configuration.getRabbitMqConfiguration();
final Host host = new Host(rabbitMqConfiguration.getRmqUri());
return new SimpleChannelProvider(rabbitMqConfiguration.getUsername(), rabbitMqConfiguration.getPassword(), rabbitMqConfiguration.getVhost(), new Address[] { new Address(host.getUri().getHost()) });
}
use of com.rabbitmq.client.Address in project spring-boot by spring-projects.
the class RabbitAutoConfigurationTests method testConnectionFactoryWithCustomConnectionNameStrategy.
@Test
@SuppressWarnings("unchecked")
void testConnectionFactoryWithCustomConnectionNameStrategy() {
this.contextRunner.withUserConfiguration(ConnectionNameStrategyConfiguration.class).run((context) -> {
CachingConnectionFactory connectionFactory = context.getBean(CachingConnectionFactory.class);
List<Address> addresses = (List<Address>) ReflectionTestUtils.getField(connectionFactory, "addresses");
assertThat(addresses).hasSize(1);
com.rabbitmq.client.ConnectionFactory rcf = mock(com.rabbitmq.client.ConnectionFactory.class);
given(rcf.newConnection(isNull(), eq(addresses), anyString())).willReturn(mock(Connection.class));
ReflectionTestUtils.setField(connectionFactory, "rabbitConnectionFactory", rcf);
connectionFactory.createConnection();
then(rcf).should().newConnection(isNull(), eq(addresses), eq("test#0"));
connectionFactory.resetConnection();
connectionFactory.createConnection();
then(rcf).should().newConnection(isNull(), eq(addresses), eq("test#1"));
});
}
Aggregations