Search in sources :

Example 36 with ConnectionFactory

use of com.rabbitmq.client.ConnectionFactory in project rabbitmq-java-client by rabbitmq.

the class ScalabilityTest method run.

public Results run() throws Exception {
    Connection con = new ConnectionFactory() {

        {
            setHost(params.host);
            setPort(params.port);
        }
    }.newConnection();
    Channel channel = con.createChannel();
    Results r = new Results(params.maxBindingExp);
    for (int y = 0; y < params.maxBindingExp; y++) {
        final int maxBindings = pow(params.base, y);
        String[] routingKeys = new String[maxBindings];
        for (int b = 0; b < maxBindings; b++) {
            routingKeys[b] = UUID.randomUUID().toString();
        }
        Stack<String> queues = new Stack<String>();
        int maxQueueExp = Math.min(params.maxQueueExp, params.maxExp - y);
        System.out.println("---------------------------------");
        System.out.println("| bindings = " + maxBindings + ", messages = " + params.messageCount);
        System.out.println("| Routing");
        int q = 0;
        // create queues & bindings, time routing
        Measurements creation = new CreationMeasurements(maxQueueExp);
        float[] routingTimes = new float[maxQueueExp];
        for (int x = 0; x < maxQueueExp; x++) {
            final int maxQueues = pow(params.base, x);
            for (; q < maxQueues; q++) {
                AMQP.Queue.DeclareOk ok = channel.queueDeclare();
                queues.push(ok.getQueue());
                for (int b = 0; b < maxBindings; b++) {
                    channel.queueBind(ok.getQueue(), "amq.direct", routingKeys[b]);
                }
            }
            creation.addDataPoint(x);
            float routingTime = timeRouting(channel, routingKeys);
            routingTimes[x] = routingTime;
            printTime(params.base, x, routingTime);
        }
        r.routingTimes[y] = routingTimes;
        float[] creationTimes = creation.analyse(params.base);
        r.creationTimes[y] = creationTimes;
        System.out.println("| Creating");
        printTimes(params.base, creationTimes);
        // delete queues & bindings
        Measurements deletion = new DeletionMeasurements(maxQueueExp);
        for (int x = maxQueueExp - 1; x >= 0; x--) {
            final int maxQueues = (x == 0) ? 0 : pow(params.base, x - 1);
            for (; q > maxQueues; q--) {
                channel.queueDelete(queues.pop());
            }
            deletion.addDataPoint(x);
        }
        float[] deletionTimes = deletion.analyse(params.base);
        r.deletionTimes[y] = deletionTimes;
        System.out.println("| Deleting");
        printTimes(params.base, deletionTimes);
    }
    channel.close();
    con.close();
    return r;
}
Also used : Channel(com.rabbitmq.client.Channel) Connection(com.rabbitmq.client.Connection) Stack(java.util.Stack) ConnectionFactory(com.rabbitmq.client.ConnectionFactory)

Example 37 with ConnectionFactory

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;
}
Also used : ConnectionFactory(com.rabbitmq.client.ConnectionFactory) Connection(com.rabbitmq.client.Connection) BlockedListener(com.rabbitmq.client.BlockedListener) IOException(java.io.IOException)

Example 38 with ConnectionFactory

use of com.rabbitmq.client.ConnectionFactory in project rabbitmq-java-client by rabbitmq.

the class ChannelLimitNegotiation method channelMaxLowerThanServerMinimum.

@Test
public void channelMaxLowerThanServerMinimum() throws Exception {
    int n = 64;
    ConnectionFactory cf = TestUtils.connectionFactory();
    cf.setRequestedChannelMax(n);
    Connection conn = cf.newConnection();
    assertEquals(n, conn.getChannelMax());
}
Also used : ConnectionFactory(com.rabbitmq.client.ConnectionFactory) AMQConnection(com.rabbitmq.client.impl.AMQConnection) Connection(com.rabbitmq.client.Connection) AutorecoveringConnection(com.rabbitmq.client.impl.recovery.AutorecoveringConnection) Test(org.junit.Test)

Example 39 with ConnectionFactory

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;
    try {
        Host.rabbitmqctl("eval 'application:set_env(rabbit, channel_max, " + n + ").'");
        ConnectionFactory cf = TestUtils.connectionFactory();
        Connection 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 {
        Host.rabbitmqctl("eval 'application:set_env(rabbit, channel_max, 0).'");
    }
}
Also used : ShutdownListener(com.rabbitmq.client.ShutdownListener) ConnectionFactory(com.rabbitmq.client.ConnectionFactory) ShutdownSignalException(com.rabbitmq.client.ShutdownSignalException) ChannelN(com.rabbitmq.client.impl.ChannelN) AMQConnection(com.rabbitmq.client.impl.AMQConnection) Connection(com.rabbitmq.client.Connection) AutorecoveringConnection(com.rabbitmq.client.impl.recovery.AutorecoveringConnection) ConsumerWorkService(com.rabbitmq.client.impl.ConsumerWorkService) IOException(java.io.IOException) Test(org.junit.Test)

Example 40 with ConnectionFactory

use of com.rabbitmq.client.ConnectionFactory in project rabbitmq-java-client by rabbitmq.

the class LoopbackUsers method getFactory.

private ConnectionFactory getFactory(String name, String addr) {
    ConnectionFactory factory = TestUtils.connectionFactory();
    factory.setUsername(name);
    factory.setPassword(name);
    factory.setHost(addr);
    return factory;
}
Also used : ConnectionFactory(com.rabbitmq.client.ConnectionFactory)

Aggregations

ConnectionFactory (com.rabbitmq.client.ConnectionFactory)64 Connection (com.rabbitmq.client.Connection)28 Test (org.junit.Test)26 IOException (java.io.IOException)17 Channel (com.rabbitmq.client.Channel)13 AMQConnection (com.rabbitmq.client.impl.AMQConnection)6 AutorecoveringConnection (com.rabbitmq.client.impl.recovery.AutorecoveringConnection)4 DefaultConsumer (com.rabbitmq.client.DefaultConsumer)3 QueueingConsumer (com.rabbitmq.client.QueueingConsumer)3 ShutdownSignalException (com.rabbitmq.client.ShutdownSignalException)3 KeyManagementException (java.security.KeyManagementException)3 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)3 TimeoutException (java.util.concurrent.TimeoutException)3 AMQP (com.rabbitmq.client.AMQP)2 Address (com.rabbitmq.client.Address)2 Consumer (com.rabbitmq.client.Consumer)2 DnsRecordIpAddressResolver (com.rabbitmq.client.DnsRecordIpAddressResolver)2 MetricsCollector (com.rabbitmq.client.MetricsCollector)2 ShutdownListener (com.rabbitmq.client.ShutdownListener)2 SslContextFactory (com.rabbitmq.client.SslContextFactory)2