Search in sources :

Example 46 with ConnectionFactory

use of com.rabbitmq.client.ConnectionFactory in project pinpoint by naver.

the class RabbitMQClient_3_3_0_to_4_0_0_IT method testPush_autorecovery.

@Test
public void testPush_autorecovery() throws Exception {
    ConnectionFactory connectionFactory = getConnectionFactory();
    connectionFactory.setAutomaticRecoveryEnabled(true);
    testRunner.runPushTest();
}
Also used : ConnectionFactory(com.rabbitmq.client.ConnectionFactory) Test(org.junit.Test)

Example 47 with ConnectionFactory

use of com.rabbitmq.client.ConnectionFactory in project pinpoint by naver.

the class RabbitMQClient_5_x_IT method testPush_nio_autorecovery.

@Test
public void testPush_nio_autorecovery() throws Exception {
    ConnectionFactory connectionFactory = getConnectionFactory();
    connectionFactory.setAutomaticRecoveryEnabled(true);
    connectionFactory.useNio();
    testRunner.runPushTest();
}
Also used : ConnectionFactory(com.rabbitmq.client.ConnectionFactory) Test(org.junit.Test)

Example 48 with ConnectionFactory

use of com.rabbitmq.client.ConnectionFactory in project beam by apache.

the class RabbitMqIOTest method testReadQueue.

@Test
public void testReadQueue() throws Exception {
    final int maxNumRecords = 10;
    PCollection<RabbitMqMessage> raw = p.apply(RabbitMqIO.read().withUri("amqp://guest:guest@localhost:" + port).withQueue("READ").withMaxNumRecords(maxNumRecords));
    PCollection<String> output = raw.apply(MapElements.into(TypeDescriptors.strings()).via((RabbitMqMessage message) -> RabbitMqTestUtils.recordToString(message.getBody())));
    List<String> records = RabbitMqTestUtils.generateRecords(maxNumRecords).stream().map(RabbitMqTestUtils::recordToString).collect(Collectors.toList());
    PAssert.that(output).containsInAnyOrder(records);
    ConnectionFactory connectionFactory = new ConnectionFactory();
    connectionFactory.setUri("amqp://guest:guest@localhost:" + port);
    Connection connection = null;
    Channel channel = null;
    try {
        connection = connectionFactory.newConnection();
        channel = connection.createChannel();
        channel.queueDeclare("READ", false, false, false, null);
        for (String record : records) {
            channel.basicPublish("", "READ", null, record.getBytes(StandardCharsets.UTF_8));
        }
        p.run();
    } finally {
        if (channel != null) {
            channel.close();
        }
        if (connection != null) {
            connection.close();
        }
    }
}
Also used : ConnectionFactory(com.rabbitmq.client.ConnectionFactory) Channel(com.rabbitmq.client.Channel) Connection(com.rabbitmq.client.Connection) Test(org.junit.Test)

Example 49 with ConnectionFactory

use of com.rabbitmq.client.ConnectionFactory in project beam by apache.

the class RabbitMqIOTest method testWriteExchange.

@Test
public void testWriteExchange() throws Exception {
    final int maxNumRecords = 1000;
    List<RabbitMqMessage> data = RabbitMqTestUtils.generateRecords(maxNumRecords).stream().map(RabbitMqMessage::new).collect(Collectors.toList());
    p.apply(Create.of(data)).apply(RabbitMqIO.write().withUri("amqp://guest:guest@localhost:" + port).withExchange("WRITE", "fanout"));
    ConnectionFactory connectionFactory = new ConnectionFactory();
    connectionFactory.setUri("amqp://guest:guest@localhost:" + port);
    Connection connection = null;
    Channel channel = null;
    try {
        connection = connectionFactory.newConnection();
        channel = connection.createChannel();
        channel.exchangeDeclare("WRITE", "fanout");
        String queueName = channel.queueDeclare().getQueue();
        channel.queueBind(queueName, "WRITE", "");
        RabbitMqTestUtils.TestConsumer consumer = new RabbitMqTestUtils.TestConsumer(channel);
        channel.basicConsume(queueName, true, consumer);
        p.run();
        while (consumer.getReceived().size() < maxNumRecords) {
            Thread.sleep(500);
        }
        assertEquals(maxNumRecords, consumer.getReceived().size());
        for (int i = 0; i < maxNumRecords; i++) {
            assertTrue(consumer.getReceived().contains("Test " + i));
        }
    } finally {
        if (channel != null) {
            channel.close();
        }
        if (connection != null) {
            connection.close();
        }
    }
}
Also used : ConnectionFactory(com.rabbitmq.client.ConnectionFactory) Channel(com.rabbitmq.client.Channel) Connection(com.rabbitmq.client.Connection) Test(org.junit.Test)

Example 50 with ConnectionFactory

use of com.rabbitmq.client.ConnectionFactory in project spring-boot by spring-projects.

the class RabbitConnectionFactoryMetricsPostProcessor method bindConnectionFactoryToRegistry.

private void bindConnectionFactoryToRegistry(MeterRegistry registry, String beanName, AbstractConnectionFactory connectionFactory) {
    ConnectionFactory rabbitConnectionFactory = connectionFactory.getRabbitConnectionFactory();
    String connectionFactoryName = getConnectionFactoryName(beanName);
    new RabbitMetrics(rabbitConnectionFactory, Tags.of("name", connectionFactoryName)).bindTo(registry);
}
Also used : ConnectionFactory(com.rabbitmq.client.ConnectionFactory) AbstractConnectionFactory(org.springframework.amqp.rabbit.connection.AbstractConnectionFactory) RabbitMetrics(org.springframework.boot.actuate.metrics.amqp.RabbitMetrics)

Aggregations

ConnectionFactory (com.rabbitmq.client.ConnectionFactory)188 Connection (com.rabbitmq.client.Connection)87 Test (org.junit.Test)73 Channel (com.rabbitmq.client.Channel)63 IOException (java.io.IOException)53 TimeoutException (java.util.concurrent.TimeoutException)23 DefaultConsumer (com.rabbitmq.client.DefaultConsumer)11 Envelope (com.rabbitmq.client.Envelope)11 SSLContext (javax.net.ssl.SSLContext)11 QueueingConsumer (com.rabbitmq.client.QueueingConsumer)9 HashMap (java.util.HashMap)9 CountDownLatch (java.util.concurrent.CountDownLatch)8 AMQP (com.rabbitmq.client.AMQP)6 Consumer (com.rabbitmq.client.Consumer)6 ShutdownSignalException (com.rabbitmq.client.ShutdownSignalException)6 AMQConnection (com.rabbitmq.client.impl.AMQConnection)6 Address (com.rabbitmq.client.Address)5 NioParams (com.rabbitmq.client.impl.nio.NioParams)4 AutorecoveringConnection (com.rabbitmq.client.impl.recovery.AutorecoveringConnection)4 Path (javax.ws.rs.Path)3