Example usage for com.rabbitmq.client Connection setId

List of usage examples for com.rabbitmq.client Connection setId

Introduction

In this page you can find the example usage for com.rabbitmq.client Connection setId.

Prototype

void setId(String id);

Source Link

Document

Sets a unique ID for this connection.

Usage

From source file:org.springframework.amqp.rabbit.junit.BrokerRunning.java

License:Apache License

@Override
public Statement apply(Statement base, Description description) {

    // Check at the beginning, so this can be used as a static field
    if (this.assumeOnline) {
        Assume.assumeTrue(brokerOnline.get(this.port));
    } else {//  w w w .j a  v  a2  s.c o m
        Assume.assumeTrue(brokerOffline.get(this.port));
    }

    ConnectionFactory connectionFactory = getConnectionFactory();

    Connection connection = null; // NOSONAR (closeResources())
    Channel channel = null;

    try {
        connection = connectionFactory.newConnection();
        connection.setId(generateId());
        channel = connection.createChannel();

        for (String queueName : this.queues) {

            if (this.purge) {
                logger.debug("Deleting queue: " + queueName);
                // Delete completely - gets rid of consumers and bindings as well
                channel.queueDelete(queueName);
            }

            if (isDefaultQueue(queueName)) {
                // Just for test probe.
                channel.queueDelete(queueName);
            } else {
                channel.queueDeclare(queueName, true, false, false, null);
            }
        }
        brokerOffline.put(this.port, false);
        if (!this.assumeOnline) {
            Assume.assumeTrue(brokerOffline.get(this.port));
        }

        if (this.management) {
            Client client = new Client(getAdminUri(), this.adminUser, this.adminPassword);
            if (!client.alivenessTest("/")) {
                throw new RuntimeException(
                        "Aliveness test failed for localhost:15672 guest/quest; " + "management not available");
            }
        }
    } catch (Exception e) {
        logger.warn("Not executing tests because basic connectivity test failed: " + e.getMessage());
        brokerOnline.put(this.port, false);
        if (this.assumeOnline) {
            if (fatal()) {
                fail("RabbitMQ Broker is required, but not available");
            } else {
                Assume.assumeNoException(e);
            }
        }
    } finally {
        closeResources(connection, channel);
    }

    return super.apply(base, description);
}

From source file:org.springframework.amqp.rabbit.junit.BrokerRunning.java

License:Apache License

/**
 * Remove any test queues that were created by an
 * {@link #isRunningWithEmptyQueues(String...)} method.
 * @param additionalQueues additional queues to remove that might have been created by
 * tests.// www.jav a2 s .  c o m
 */
public void removeTestQueues(String... additionalQueues) {
    List<String> queuesToRemove = Arrays.asList(this.queues);
    if (additionalQueues != null) {
        queuesToRemove = new ArrayList<>(queuesToRemove);
        queuesToRemove.addAll(Arrays.asList(additionalQueues));
    }
    logger.debug("deleting test queues: " + queuesToRemove);
    ConnectionFactory connectionFactory = getConnectionFactory();
    Connection connection = null; // NOSONAR (closeResources())
    Channel channel = null;

    try {
        connection = connectionFactory.newConnection();
        connection.setId(generateId() + ".queueDelete");
        channel = connection.createChannel();

        for (String queue : queuesToRemove) {
            channel.queueDelete(queue);
        }
    } catch (Exception e) {
        logger.warn("Failed to delete queues", e);
    } finally {
        closeResources(connection, channel);
    }
}

From source file:org.springframework.amqp.rabbit.junit.BrokerRunning.java

License:Apache License

/**
 * Delete arbitrary queues from the broker.
 * @param queues the queues to delete./*from w  w w.  j  a  va 2s . co  m*/
 */
public void deleteQueues(String... queues) {
    ConnectionFactory connectionFactory = getConnectionFactory();
    Connection connection = null; // NOSONAR (closeResources())
    Channel channel = null;

    try {
        connection = connectionFactory.newConnection();
        connection.setId(generateId() + ".queueDelete");
        channel = connection.createChannel();

        for (String queue : queues) {
            channel.queueDelete(queue);
        }
    } catch (Exception e) {
        logger.warn("Failed to delete queues", e);
    } finally {
        closeResources(connection, channel);
    }
}

From source file:org.springframework.amqp.rabbit.junit.BrokerRunning.java

License:Apache License

/**
 * Delete arbitrary exchanges from the broker.
 * @param exchanges the exchanges to delete.
 *//*from w w w.j  a va  2  s .c om*/
public void deleteExchanges(String... exchanges) {
    ConnectionFactory connectionFactory = getConnectionFactory();
    Connection connection = null; // NOSONAR (closeResources())
    Channel channel = null;

    try {
        connection = connectionFactory.newConnection();
        connection.setId(generateId() + ".exchangeDelete");
        channel = connection.createChannel();

        for (String exchange : exchanges) {
            channel.exchangeDelete(exchange);
        }
    } catch (Exception e) {
        logger.warn("Failed to delete queues", e);
    } finally {
        closeResources(connection, channel);
    }
}