Example usage for com.rabbitmq.client Channel queueDelete

List of usage examples for com.rabbitmq.client Channel queueDelete

Introduction

In this page you can find the example usage for com.rabbitmq.client Channel queueDelete.

Prototype

Queue.DeleteOk queueDelete(String queue) throws IOException;

Source Link

Document

Delete a queue, without regard for whether it is in use or has messages on it

Usage

From source file:net.es.netshell.rabbitmq.CreateToken.java

License:Open Source License

public CreateToken(BrokerInfo info, Channel tokenChannel, String listenerID) throws Exception {
    // Info on data needed to create a connection
    this.info = info;

    // Create random UUID for producer's temporary queue
    String uuid = UUID.randomUUID().toString();
    // Declare this temporary queue and start listening (exclusive queue).
    tokenChannel.queueDeclare(uuid, false, true, true, null);
    QueueingConsumer consumer = new QueueingConsumer(tokenChannel);

    // Send TOKEN_REQUEST with current username.
    String message = "TOKEN_REQUEST" + ":" + uuid + ":"
            + KernelThread.currentKernelThread().getUser().getName();

    tokenChannel.basicPublish("", listenerID, null, message.getBytes());
    // Start consuming to receive token.
    tokenChannel.basicConsume(uuid, true, "tokenRequest", false, false, null, consumer);
    QueueingConsumer.Delivery delivery = consumer.nextDelivery();

    // When token is received, store in "token."
    token = new String(delivery.getBody());
    // Delete temporary queue
    tokenChannel.queueDelete(uuid);
}

From source file:org.apache.cloudstack.mom.rabbitmq.RabbitMQEventBus.java

License:Apache License

@Override
public boolean stop() {

    if (_connection.isOpen()) {
        for (String subscriberId : _subscribers.keySet()) {
            Ternary<String, Channel, EventSubscriber> subscriberDetails = _subscribers.get(subscriberId);
            Channel channel = subscriberDetails.second();
            String queueName = subscriberId;
            try {
                channel.queueDelete(queueName);
                channel.abort();/*from w ww . j a  v  a  2  s. c  o  m*/
            } catch (IOException ioe) {
                s_logger.warn(
                        "Failed to delete queue: " + queueName + " on AMQP server due to " + ioe.getMessage());
            }
        }
    }

    closeConnection();
    return true;
}

From source file:org.axonframework.amqp.eventhandling.RabbitMQBenchmark.java

License:Apache License

private static String refreshQueue(Channel channel, String queueName) throws IOException {
    channel.queueDelete(queueName);
    queueName = channel.queueDeclare().getQueue();
    return queueName;
}

From source file:org.mule.transport.amqp.harness.rules.AmqpModelCleanupRule.java

License:Open Source License

protected void cleanQueues(String[] queues, Channel channel) throws IOException {
    for (String queue : queues) {
        channel.queueDelete(queue);
    }/*from   w w w. j a v  a 2 s.c o  m*/
}

From source file:org.mule.transport.amqp.harness.rules.AmqpModelRule.java

License:Open Source License

protected void undoQueuesConfiguration(Configuration configuration, Channel channel) throws IOException {
    List<Queue> configurationQueues = configuration.getQueues();

    for (Queue queue : configurationQueues) {
        channel.queueDelete(queue.getName());
    }// w w w.j  a  va2  s.com
}

From source file:org.objectweb.proactive.extensions.amqp.federation.AMQPFederationRemoteObjectServer.java

License:Open Source License

@Override
protected byte[] handleMessage(Channel channel, BasicProperties props, byte[] body) throws IOException {
    if (DELETE_QUEUE_MESSAGE_TYPE.equals(props.getType())) {
        channel.queueDelete(queueName);
        return null;
    } else if (PING_MESSAGE_TYPE.equals(props.getType())) {
        return new byte[] {};
    } else {/* ww w.j a  v  a 2 s . c  om*/
        return null;
    }
}

From source file:org.openbaton.plugin.utils.PluginCaller.java

License:Apache License

public Serializable executeRPC(String methodName, Collection<Serializable> args, Type returnType)
        throws IOException, InterruptedException, PluginException {

    Channel channel = connection.createChannel();
    String replyQueueName = channel.queueDeclare().getQueue();
    String exchange = "plugin-exchange";
    channel.queueBind(replyQueueName, exchange, replyQueueName);
    QueueingConsumer consumer = new QueueingConsumer(channel);
    String consumerTag = channel.basicConsume(replyQueueName, true, consumer);

    //Check if plugin is still up
    if (!RabbitManager.getQueues(brokerIp, username, password, managementPort).contains(pluginId))
        throw new PluginException("Plugin with id: " + pluginId + " not existing anymore...");

    String response;/*from ww w.  jav  a2 s.  c  o m*/
    String corrId = UUID.randomUUID().toString();
    PluginMessage pluginMessage = new PluginMessage();
    pluginMessage.setMethodName(methodName);
    pluginMessage.setParameters(args);
    String message = gson.toJson(pluginMessage);

    BasicProperties props = new Builder().correlationId(corrId).replyTo(replyQueueName).build();

    channel.basicPublish(exchange, pluginId, props, message.getBytes());

    if (returnType != null) {

        while (true) {
            Delivery delivery = consumer.nextDelivery();
            if (delivery.getProperties().getCorrelationId().equals(corrId)) {
                response = new String(delivery.getBody());
                log.trace("received: " + response);
                break;
            } else {
                log.error("Received Message with wrong correlation id");
                throw new PluginException(
                        "Received Message with wrong correlation id. This should not happen, if it does please call us.");
            }
        }

        channel.queueDelete(replyQueueName);
        try {
            channel.close();
        } catch (TimeoutException e) {
            e.printStackTrace();
        }
        JsonObject jsonObject = gson.fromJson(response, JsonObject.class);

        JsonElement exceptionJson = jsonObject.get("exception");
        if (exceptionJson == null) {
            JsonElement answerJson = jsonObject.get("answer");

            Serializable ret = null;

            if (answerJson.isJsonPrimitive()) {
                ret = gson.fromJson(answerJson.getAsJsonPrimitive(), returnType);
            } else if (answerJson.isJsonArray()) {
                ret = gson.fromJson(answerJson.getAsJsonArray(), returnType);
            } else
                ret = gson.fromJson(answerJson.getAsJsonObject(), returnType);

            log.trace("answer is: " + ret);
            return ret;
        } else {
            PluginException pluginException;
            try {
                pluginException = new PluginException(
                        gson.fromJson(exceptionJson.getAsJsonObject(), VimDriverException.class));
                log.debug("Got Vim Driver Exception with server: "
                        + ((VimDriverException) pluginException.getCause()).getServer());
            } catch (Exception ignored) {
                pluginException = new PluginException(
                        gson.fromJson(exceptionJson.getAsJsonObject(), Throwable.class));
            }
            throw pluginException;
        }
    } else
        return null;
}

From source file:org.opendaylight.federationmessagequeue.impl.RabbitMessageBus.java

License:Open Source License

@Override
public void destroyQueue(String queueName) {
    LOG.info("Started delete of queue {}", queueName);

    // lookup connection by queueName
    MessageBusConnectionData messageBusConnectionData = queueNameToConnectionData.get(queueName);
    if (messageBusConnectionData != null) {
        // get channel from active connections map
        Channel channel = messageBusConnectionData.channel;
        String brokerIp = messageBusConnectionData.brokerIp;
        Connection conn = messageBusConnectionData.conn;
        try {//www . j  a  v  a2 s  .co m
            // kill the queue dont wait for confirmation
            if (channel != null) {
                try {
                    channel.queueDelete(queueName);
                    LOG.info("Deleted queue {} successfully", queueName);
                } catch (IOException e) {
                    LOG.warn("Failed to delete queue {} msg: {}", queueName, e.getMessage());
                }
                channel.close();
            } else {
                LOG.warn("Null channel while deleting queue {} on broker {}", queueName, brokerIp);
            }
            if (conn != null) {
                conn.close();
            } else {
                LOG.warn("Null connection while deleting queue {} on broker {}", queueName, brokerIp);
            }
        } catch (IOException | TimeoutException e) {
            LOG.warn("Failed to close channel while deleting queue {} on broker {}", queueName, brokerIp, e);
        }
        // remove the queue from the internal queue list
        queueNameToConnectionData.remove(queueName);
    } else {
        LOG.warn("Cancelled deletion of queue {} because queueName not found in queueNameToConnectionData",
                queueName);
    }

}

From source file:org.springframework.amqp.rabbit.core.RabbitAdmin.java

License:Apache License

@Override
@ManagedOperation/*from w w w  .  j av  a2 s.  c o  m*/
public boolean deleteQueue(final String queueName) {
    return this.rabbitTemplate.execute(new ChannelCallback<Boolean>() {
        @Override
        public Boolean doInRabbit(Channel channel) throws Exception {
            try {
                channel.queueDelete(queueName);
            } catch (IOException e) {
                return false;
            }
            return true;
        }
    });
}

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 {//from   w  ww  . j a v  a  2s.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);
}