Example usage for com.rabbitmq.client Channel close

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

Introduction

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

Prototype

@Override
void close() throws IOException, TimeoutException;

Source Link

Document

Close this channel with the com.rabbitmq.client.AMQP#REPLY_SUCCESS close code and message 'OK'.

Usage

From source file:dk.getcreditscore.messaging.Send.java

public static void sendMessage(String message) throws IOException {
    ConnectionFactory factory = new ConnectionFactory();
    factory.setHost("datdb.cphbusiness.dk");
    factory.setUsername("student");
    factory.setPassword("cph");
    Connection connection = factory.newConnection();
    Channel channel = connection.createChannel();

    channel.queueDeclare(TASK_QUEUE_NAME, true, false, false, null);

    channel.basicPublish("", TASK_QUEUE_NAME, MessageProperties.PERSISTENT_TEXT_PLAIN, message.getBytes());

    channel.close();
    connection.close();/*w  w w  .j  a  va  2 s  .com*/
}

From source file:dummyloanbroker.DummyLoanBroker.java

public static void main(String[] args) throws IOException {
    ConnectionFactory factory = new ConnectionFactory();
    factory.setHost("datdb.cphbusiness.dk");
    factory.setUsername("student");
    factory.setPassword("cph");
    com.rabbitmq.client.Connection connection = factory.newConnection();
    com.rabbitmq.client.Channel channel = connection.createChannel();
    String corrId = java.util.UUID.randomUUID().toString();

    LoanRequestDTO loanRequest = new LoanRequestDTO("123456-7890", 456289.0, 25, -1);

    Gson gson = new Gson();

    String message = gson.toJson(loanRequest);

    AMQP.BasicProperties props = new AMQP.BasicProperties.Builder().correlationId(corrId).build();
    channel.queueDeclare(TASK_QUEUE_NAME, true, false, false, null);

    channel.basicPublish("", TASK_QUEUE_NAME, props, message.getBytes());

    channel.close();
    connection.close();/*w  ww .  j  a v  a 2s  . c  om*/
}

From source file:edu.iit.rabbitmq.Send.java

/**
 *
 * @param message/*from www.ja  v  a  2s  . c  om*/
 * @throws Exception
 */
public void sendMessage(String message) throws Exception {

    ConnectionFactory factory = new ConnectionFactory();
    factory.setHost(RABBITMQ);
    Connection connection = factory.newConnection();
    Channel channel = connection.createChannel();
    try {
        channel.queueDeclare(QUEUENAME, false, false, false, null);
    } catch (Exception e) {
        System.out.println("Queue already exists, moving on");
    }

    channel.basicPublish("", QUEUENAME, null, message.getBytes("UTF-8"));
    System.out.println(" [x] Sent '" + message + "'");

    channel.close();
    connection.close();
}

From source file:edu.jhu.pha.vospace.QueueConnector.java

License:Apache License

public static void close(Channel c) {
    if (c != null) {
        try {/*from   w  w w .  j av a 2  s. co m*/
            c.close();
        } catch (Exception ignored) {
        }
    }
}

From source file:edu.kit.dama.util.test.RabbitMQTest.java

License:Apache License

public static void main(String[] args) throws IOException, TimeoutException {
    ConnectionFactory factory = new ConnectionFactory();
    factory.setHost("localhost");
    Connection connection = factory.newConnection();
    Channel channel = connection.createChannel();

    channel.exchangeDeclare(EXCHANGE_NAME, "fanout", true, false, false, null);
    //channel.queueDeclare(QUEUE_NAME, true, false, false, null);
    /*String queueName = channel.queueDeclare().getQueue();
    channel.queueBind(queueName, EXCHANGE_NAME, "");*/

    String message = "Hello!";

    channel.basicPublish(EXCHANGE_NAME, "", MessageProperties.MINIMAL_PERSISTENT_BASIC, message.getBytes());
    System.out.println(" [x] Sent '" + message + "'");

    channel.close();
    connection.close();//w ww  .  j a  v a2 s. co m

}

From source file:es.devcircus.rabbitmq_examples.rabbitmq_hello_world.Send.java

License:Open Source License

/**
 * /*ww w.  j a  v  a 2s.co  m*/
 * @param argv
 * @throws Exception 
 */
public static void main(String[] argv) throws Exception {

    ConnectionFactory factory = new ConnectionFactory();
    factory.setHost("localhost");
    Connection connection = factory.newConnection();
    Channel channel = connection.createChannel();

    channel.queueDeclare(QUEUE_NAME, false, false, false, null);
    String message = "Hello World!";
    channel.basicPublish("", QUEUE_NAME, null, message.getBytes());
    System.out.println(" [x] Sent '" + message + "'");

    channel.close();
    connection.close();
}

From source file:es.devcircus.rabbitmq_examples.rabbitmq_publish_subscribe.EmitLog.java

License:Open Source License

/**
 *
 * @param argv/*from  w w  w .  j av a  2 s  .c o  m*/
 * @throws Exception
 */
public static void main(String[] argv) throws Exception {

    ConnectionFactory factory = new ConnectionFactory();
    factory.setHost("localhost");
    Connection connection = factory.newConnection();
    Channel channel = connection.createChannel();

    channel.exchangeDeclare(EXCHANGE_NAME, "fanout");

    String message = getMessage(argv);

    channel.basicPublish(EXCHANGE_NAME, "", null, message.getBytes());
    System.out.println(" [x] Sent '" + message + "'");

    channel.close();
    connection.close();
}

From source file:es.devcircus.rabbitmq_examples.rabbitmq_routing.EmitLogDirect.java

License:Open Source License

/**
 *
 * @param argv//w w  w .j  a v a2s. c om
 * @throws Exception
 */
public static void main(String[] argv) throws Exception {

    ConnectionFactory factory = new ConnectionFactory();
    //        factory.setHost("localhost");
    factory.setHost("192.168.0.202");
    Connection connection = factory.newConnection();
    Channel channel = connection.createChannel();

    channel.exchangeDeclare(EXCHANGE_NAME, "direct");

    String severity = getSeverity(argv);
    String message = getMessage(argv);

    channel.basicPublish(EXCHANGE_NAME, severity, null, message.getBytes());
    System.out.println(" [x] Sent '" + severity + "':'" + message + "'");

    channel.close();
    connection.close();
}

From source file:es.devcircus.rabbitmq_examples.rabbitmq_work_queues.NewTask.java

License:Open Source License

/**
 * // w  w w.j a  va  2s. c o  m
 * @param argv
 * @throws Exception 
 */
public static void main(String[] argv) throws Exception {

    ConnectionFactory factory = new ConnectionFactory();
    factory.setHost("localhost");
    Connection connection = factory.newConnection();
    Channel channel = connection.createChannel();

    channel.queueDeclare(TASK_QUEUE_NAME, true, false, false, null);

    String message = getMessage(argv);

    channel.basicPublish("", TASK_QUEUE_NAME, MessageProperties.PERSISTENT_TEXT_PLAIN, message.getBytes());
    System.out.println(" [x] Sent '" + message + "'");

    channel.close();
    connection.close();
}

From source file:genqa.ExportRabbitMQVerifier.java

License:Open Source License

public void run() throws IOException, InterruptedException {
    final Connection connection = m_connFactory.newConnection();
    final Channel channel = connection.createChannel();

    try {//w  w w  . j  a va 2s  . c o  m
        channel.exchangeDeclare(m_exchangeName, "topic", true);
        String dataQueue = channel.queueDeclare().getQueue();
        channel.queueBind(dataQueue, m_exchangeName, "EXPORT_PARTITIONED_TABLE.#");
        channel.queueBind(dataQueue, m_exchangeName, "EXPORT_PARTITIONED_TABLE2.#");
        channel.queueBind(dataQueue, m_exchangeName, "EXPORT_REPLICATED_TABLE.#");
        channel.queueBind(dataQueue, m_exchangeName, "EXPORT_PARTITIONED_TABLE_FOO.#");
        channel.queueBind(dataQueue, m_exchangeName, "EXPORT_PARTITIONED_TABLE2_FOO.#");
        channel.queueBind(dataQueue, m_exchangeName, "EXPORT_REPLICATED_TABLE_FOO.#");
        String doneQueue = channel.queueDeclare().getQueue();
        channel.queueBind(doneQueue, m_exchangeName, "EXPORT_DONE_TABLE.#");
        channel.queueBind(doneQueue, m_exchangeName, "EXPORT_DONE_TABLE_FOO.#");

        // Setup callback for data stream
        channel.basicConsume(dataQueue, false, createConsumer(channel));

        // Setup callback for the done message
        QueueingConsumer doneConsumer = new QueueingConsumer(channel);
        channel.basicConsume(doneQueue, true, doneConsumer);

        // Wait until the done message arrives, then verify count
        final QueueingConsumer.Delivery doneMsg = doneConsumer.nextDelivery();
        final long expectedRows = Long.parseLong(ExportOnServerVerifier.RoughCSVTokenizer
                .tokenize(new String(doneMsg.getBody(), Charsets.UTF_8))[6]);

        while (expectedRows > m_verifiedRows) {
            Thread.sleep(1000);
            System.err.println("Expected " + expectedRows + " " + m_verifiedRows);
        }
    } finally {
        tearDown(channel);
        channel.close();
        connection.close();
    }
}