Example usage for com.rabbitmq.client Channel queueDeclare

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

Introduction

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

Prototype

Queue.DeclareOk queueDeclare(String queue, boolean durable, boolean exclusive, boolean autoDelete,
        Map<String, Object> arguments) throws IOException;

Source Link

Document

Declare a queue

Usage

From source file:brooklyn.entity.messaging.rabbit.RabbitEc2LiveTest.java

License:Apache License

@Override
protected void doTest(Location loc) throws Exception {
    RabbitBroker rabbit = app.createAndManageChild(EntitySpec.create(RabbitBroker.class));
    rabbit.start(ImmutableList.of(loc));
    EntityTestUtils.assertAttributeEqualsEventually(rabbit, RabbitBroker.SERVICE_UP, true);

    byte[] content = "MessageBody".getBytes(Charsets.UTF_8);
    String queue = "queueName";
    Channel producer = null;
    Channel consumer = null;//w  w  w.ja  v  a2s . c  om
    try {
        producer = getAmqpChannel(rabbit);
        consumer = getAmqpChannel(rabbit);

        producer.queueDeclare(queue, true, false, false, Maps.<String, Object>newHashMap());
        producer.queueBind(queue, AmqpExchange.DIRECT, queue);
        producer.basicPublish(AmqpExchange.DIRECT, queue, null, content);

        QueueingConsumer queueConsumer = new QueueingConsumer(consumer);
        consumer.basicConsume(queue, true, queueConsumer);

        QueueingConsumer.Delivery delivery = queueConsumer.nextDelivery();
        assertEquals(delivery.getBody(), content);
    } finally {
        if (producer != null)
            producer.close();
        if (consumer != null)
            consumer.close();
    }
}

From source file:brooklyn.entity.messaging.rabbit.RabbitIntegrationTest.java

License:Apache License

/**
 * Test that an AMQP client can connect to and use the broker.
 *//*from  w ww  . j  a  v  a 2  s . co  m*/
@Test(groups = { "Integration", "WIP" })
public void testClientConnection() throws Exception {
    rabbit = app.createAndManageChild(EntitySpec.create(RabbitBroker.class));
    rabbit.start(ImmutableList.of(testLocation));
    EntityTestUtils.assertAttributeEqualsEventually(rabbit, Startable.SERVICE_UP, true);

    byte[] content = "MessageBody".getBytes(Charsets.UTF_8);
    String queue = "queueName";
    Channel producer = null;
    Channel consumer = null;
    try {
        producer = getAmqpChannel(rabbit);
        consumer = getAmqpChannel(rabbit);

        producer.queueDeclare(queue, true, false, false, ImmutableMap.<String, Object>of());
        producer.queueBind(queue, AmqpExchange.DIRECT, queue);
        producer.basicPublish(AmqpExchange.DIRECT, queue, null, content);

        QueueingConsumer queueConsumer = new QueueingConsumer(consumer);
        consumer.basicConsume(queue, true, queueConsumer);

        QueueingConsumer.Delivery delivery = queueConsumer.nextDelivery(60 * 1000l); // one minute timeout
        assertEquals(delivery.getBody(), content);
    } finally {
        closeSafely(producer, 10 * 1000);
        closeSafely(consumer, 10 * 1000);
    }
}

From source file:Colas.Colas.java

private String reciver(String enviar) {
    try {/* ww  w . j  av a2s . c o m*/
        ConnectionFactory factory = new ConnectionFactory();
        factory.setHost(IP);
        factory.setPort(5672);
        factory.setUsername("valencia");
        factory.setPassword("admin123");

        Connection connection = factory.newConnection();
        Channel channel = connection.createChannel();

        channel.queueDeclare("SC", false, false, false, null);

        channel.basicPublish("", "SC", null, enviar.getBytes());
        System.out.println(" [x] Sent '" + enviar + "'");
        channel.close();
        connection.close();
    } catch (Exception e) {
        System.out.println("Error enviando ");
        e.printStackTrace();
    }
    try {
        ConnectionFactory factory = new ConnectionFactory();
        factory.setHost("localhost");
        factory.setUsername("guest");
        factory.setPassword("admin123");
        Connection connection = factory.newConnection();
        Channel channel = connection.createChannel();
        channel.queueDeclare("CF", false, false, false, null);
        System.out.println(" [*] Waiting for messages. To exit press CTRL+C");
        QueueingConsumer consumer = new QueueingConsumer(channel);
        channel.basicConsume("CF", true, consumer);
        while (true) {
            QueueingConsumer.Delivery delivery = consumer.nextDelivery();
            String message = new String(delivery.getBody());
            System.out.println(" [x] Received '" + message + "'");
            return message;

        }
    } catch (Exception e) {
        System.out.println("Error reciviendo ");
        e.printStackTrace();
    }
    return "Error";

}

From source file:Colas.Colas.java

private void sender(String string) {
    try {/*from   w w  w  . j  a  va 2  s.c  o m*/
        ConnectionFactory factory = new ConnectionFactory();
        factory.setHost("localhost");
        factory.setPort(5672);
        factory.setUsername("valencia");
        factory.setPassword("admin123");

        Connection connection = factory.newConnection();
        Channel channel = connection.createChannel();

        channel.queueDeclare("SC", false, false, false, null);

        channel.basicPublish("", "SC", null, string.getBytes());
        System.out.println(" [x] Sent '" + string + "'");
        channel.close();
        connection.close();
    } catch (Exception e) {
        System.out.println("Error enviando ");
        e.printStackTrace();
    }
}

From source file:Colas.Colas.java

@Override
public void run() {
    try {//w  ww  .j a  v a2  s .co  m
        ConnectionFactory factory = new ConnectionFactory();
        factory.setHost("localhost");
        factory.setUsername("guest");
        factory.setPassword("admin123");
        Connection connection = factory.newConnection();
        Channel channel = connection.createChannel();
        channel.queueDeclare("CF", false, false, false, null);
        System.out.println(" [*] Waiting for messages. To exit press CTRL+C");
        QueueingConsumer consumer = new QueueingConsumer(channel);
        channel.basicConsume("CF", true, consumer);
        while (true) {
            QueueingConsumer.Delivery delivery = consumer.nextDelivery();
            String message = new String(delivery.getBody());
            System.out.println(" [x] Received '" + message + "'");
            String[] resp = message.split(";");
            String p = resp[0];
            if (p.equals("Q1")) {
                pregunta1(resp[1]);
            }
            if (p.equals("Q2")) {
                pregunta2(resp[1]);
            }
            if (p.equals("Q3")) {
                pregunta3(resp[1]);
            }
            if (p.equals("Q4")) {
                pregunta4(resp[1]);
            }

        }
    } catch (Exception e) {
        System.out.println("Error reciviendo ");
        e.printStackTrace();
    }
}

From source file:com.abiquo.commons.amqp.impl.am.AMConfiguration.java

License:Open Source License

@Override
public void declareQueues(Channel channel) throws IOException {
    channel.queueDeclare(AM_QUEUE, Durable, NonExclusive, NonAutodelete, null);
    channel.queueBind(AM_QUEUE, AM_EXCHANGE, AM_ROUTING_KEY);
}

From source file:com.abiquo.commons.amqp.impl.datacenter.DatacenterNotificationConfiguration.java

License:Open Source License

@Override
public void declareQueues(Channel channel) throws IOException {
    channel.queueDeclare(NOTIFICATIONS_QUEUE, Durable, NonExclusive, NonAutodelete, null);
    channel.queueBind(NOTIFICATIONS_QUEUE, NOTIFICATIONS_EXCHANGE, NOTIFICATIONS_ROUTING_KEY);
}

From source file:com.abiquo.commons.amqp.impl.datacenter.DatacenterRequestConfiguration.java

License:Open Source License

@Override
public void declareQueues(Channel channel) throws IOException {
    channel.queueDeclare(buildJobsQueue(datacenterId, type), Durable, NonExclusive, NonAutodelete, null);
    channel.queueBind(buildJobsQueue(datacenterId, type), getDatacenterExchange(),
            buildJobsRoutingKey(datacenterId, type));
}

From source file:com.abiquo.commons.amqp.impl.ha.HAConfiguration.java

License:Open Source License

@Override
public void declareQueues(Channel channel) throws IOException {
    channel.queueDeclare(HA_QUEUE, Durable, NonExclusive, NonAutodelete, null);
    channel.queueBind(HA_QUEUE, HA_EXCHANGE, HA_ROUTING_KEY);
}

From source file:com.abiquo.commons.amqp.impl.tracer.TracerConfiguration.java

License:Open Source License

@Override
public void declareQueues(Channel channel) throws IOException {
    channel.queueDeclare(TRACER_QUEUE, Durable, NonExclusive, NonAutodelete, null);
    channel.queueBind(TRACER_QUEUE, TRACER_EXCHANGE, TRACER_ROUTING_KEY);
}