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:workqueue.NewTask.java

public static void main(String[] argv) throws Exception {
    ConnectionFactory factory = new ConnectionFactory();
    factory.setHost("datdb.cphbusiness.dk");
    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("UTF-8"));
    System.out.println(" [x] Sent '" + message + "'");

    channel.close();//from   ww w . j  a  v a  2  s .  c o  m
    connection.close();
}

From source file:workqueue.Worker.java

public static void main(String[] argv) throws Exception {
    ConnectionFactory factory = new ConnectionFactory();
    factory.setHost("datdb.cphbusiness.dk");
    final Connection connection = factory.newConnection();
    final Channel channel = connection.createChannel();

    channel.queueDeclare(TASK_QUEUE_NAME, true, false, false, null);
    System.out.println(" [*] Waiting for messages. To exit press CTRL+C");

    channel.basicQos(1);//  ww w. java 2 s  . c o  m

    final Consumer consumer = new DefaultConsumer(channel) {
        @Override
        public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties,
                byte[] body) throws IOException {
            String message = new String(body, "UTF-8");

            System.out.println(" [x] Received '" + message + "'");
            try {
                doWork(message);
            } finally {
                System.out.println(" [x] Done");
                channel.basicAck(envelope.getDeliveryTag(), false);
            }
        }
    };
    channel.basicConsume(TASK_QUEUE_NAME, false, consumer);
}

From source file:wunderrabbit.RabbitConnection.java

License:Apache License

protected void declareQueue(Channel channel, Endpoint<String> endpoint) throws Exception {
    channel.queueDeclare(endpoint.implementation(), endpoint.isDurable(), false, false, null);
}

From source file:zipkin2.collector.rabbitmq.ITRabbitMQCollector.java

License:Apache License

/** See GitHub issue #2068 */
@Test//w  w  w .  j ava2  s.  c  o m
public void startsWhenConfiguredQueueAlreadyExists() throws IOException, TimeoutException {
    Channel channel = rabbit.collector.connection.get().createChannel();
    // make a queue with non-default properties
    channel.queueDeclare("zipkin-test2", true, false, false,
            Collections.singletonMap("x-message-ttl", 36000000));
    try {
        RabbitMQCollector.builder().storage(InMemoryStorage.newBuilder().build())
                .metrics(CollectorMetrics.NOOP_METRICS).queue("zipkin-test2")
                .addresses(Collections.singletonList(rabbit.address())).build().start().close();
    } finally {
        channel.queueDelete("zipkin-test2");
        channel.close();
    }
}

From source file:zipkin2.reporter.amqp.RabbitMQSenderTest.java

License:Apache License

private void declareQueue(String queue) throws Exception {
    Channel channel = sender.get().createChannel();
    try {//from w ww  .j a va 2  s  . co m
        channel.queueDelete(queue);
        channel.queueDeclare(queue, false, true, true, null);
    } finally {
        channel.close();
    }
    Thread.sleep(500L);
}