Example usage for com.rabbitmq.client Envelope getDeliveryTag

List of usage examples for com.rabbitmq.client Envelope getDeliveryTag

Introduction

In this page you can find the example usage for com.rabbitmq.client Envelope getDeliveryTag.

Prototype

public long getDeliveryTag() 

Source Link

Document

Get the delivery tag included in this parameter envelope

Usage

From source file:uk.ac.soton.itinnovation.experimedia.arch.ecc.amqpAPI.impl.amqp.AMQPBasicSubscriptionProcessor.java

@Override
public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body)
        throws IOException {
    try {//from  www. j ava 2  s  .co  m
        messageDispatch.addMessage(queueName, body);

        getChannel().basicAck(envelope.getDeliveryTag(), false);
    } catch (IOException ioe) {
        subProcLogger.error("Could not send AMQP acknowledgement");
        throw ioe;
    }
}

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);//w w w.j a va2 s .co  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:xyz.cloudbans.barker.amqp.BarkerConsumer.java

License:Apache License

@Override
public void handleDelivery(String consumerTag, final Envelope envelope, AMQP.BasicProperties properties,
        final byte[] body) throws IOException {
    // Block until subscription is available
    if (subscription == null) {
        synchronized (lock) {
            try {
                lock.wait();/*ww  w.  jav a  2 s. co m*/
            } catch (InterruptedException ignore) {
            }
        }
    }

    listener.onMessage(subscription, new Message() {
        @Override
        public void acknowledge() {
            try {
                getChannel().basicAck(envelope.getDeliveryTag(), false);
            } catch (IOException e) {
                throw new BarkerException("An exception occurred while acknowledging message.", e);
            }
        }

        @Override
        public void requeue() {
            try {
                getChannel().basicReject(envelope.getDeliveryTag(), true);
            } catch (IOException e) {
                throw new BarkerException("An exception occurred while requeue message.", e);
            }
        }

        @Override
        public byte[] getBody() {
            return Arrays.copyOf(body, body.length);
        }
    });
}