Search in sources :

Example 6 with Address

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());
    }
}
Also used : Address(com.rabbitmq.client.Address) URI(java.net.URI)

Example 7 with Address

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());
    }
}
Also used : ConnectionFactory(com.rabbitmq.client.ConnectionFactory) Address(com.rabbitmq.client.Address) Connection(com.rabbitmq.client.Connection) Test(org.junit.Test)

Example 8 with Address

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");
}
Also used : ConnectionFactory(com.rabbitmq.client.ConnectionFactory) Address(com.rabbitmq.client.Address) Test(org.junit.Test)

Example 9 with Address

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()) });
}
Also used : Address(com.rabbitmq.client.Address) RabbitMqConfiguration(com.godaddy.pubsub.configurations.RabbitMqConfiguration) SimpleChannelProvider(io.paradoxical.rabbitmq.connectionManagment.SimpleChannelProvider) Host(io.paradoxical.rabbitmq.connectionManagment.Host) LazySingleton(com.netflix.governator.guice.lazy.LazySingleton) Provides(com.google.inject.Provides)

Example 10 with Address

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"));
    });
}
Also used : Address(com.rabbitmq.client.Address) CachingConnectionFactory(org.springframework.amqp.rabbit.connection.CachingConnectionFactory) Connection(com.rabbitmq.client.Connection) List(java.util.List) Test(org.junit.jupiter.api.Test)

Aggregations

Address (com.rabbitmq.client.Address)12 Test (org.junit.Test)6 Connection (com.rabbitmq.client.Connection)4 ConnectionFactory (com.rabbitmq.client.ConnectionFactory)4 MetricsCollector (com.rabbitmq.client.MetricsCollector)2 ConnectionParams (com.rabbitmq.client.impl.ConnectionParams)2 FrameHandler (com.rabbitmq.client.impl.FrameHandler)2 ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)2 RabbitMqConfiguration (com.godaddy.pubsub.configurations.RabbitMqConfiguration)1 Provides (com.google.inject.Provides)1 LazySingleton (com.netflix.governator.guice.lazy.LazySingleton)1 AddressResolver (com.rabbitmq.client.AddressResolver)1 DnsSrvRecordAddressResolver (com.rabbitmq.client.DnsSrvRecordAddressResolver)1 AMQConnection (com.rabbitmq.client.impl.AMQConnection)1 FrameHandlerFactory (com.rabbitmq.client.impl.FrameHandlerFactory)1 RecoveryAwareAMQConnection (com.rabbitmq.client.impl.recovery.RecoveryAwareAMQConnection)1 RecoveryAwareAMQConnectionFactory (com.rabbitmq.client.impl.recovery.RecoveryAwareAMQConnectionFactory)1 Host (io.paradoxical.rabbitmq.connectionManagment.Host)1 SimpleChannelProvider (io.paradoxical.rabbitmq.connectionManagment.SimpleChannelProvider)1 FileInputStream (java.io.FileInputStream)1