Package com.rabbitmq.client

Examples of com.rabbitmq.client.QueueingConsumer$Delivery


            int msgCount = 0;
            String queueName = "ManyConnections";
            ch.queueDeclare(queueName, false, false, false, null);

            QueueingConsumer consumer = new QueueingConsumer(ch);
            ch.basicConsume(queueName, true, consumer);
            while (true) {
                String toSend = threadNumber + "/" + msgCount++;
                ch.basicPublish("", queueName, null, toSend.getBytes());
                Thread.sleep(delayLen);

                QueueingConsumer.Delivery delivery = consumer.nextDelivery();
                if (threadNumber == 0) {
                    long now = System.currentTimeMillis();
                    double delta = (now - startTime) / 1000.0;
                    double actualRate = msgCount / delta;
                    double totalRate = totalCount() * actualRate;
 
View Full Code Here


    }
    ch.exchangeDeclare(exchange, exchangeType);
    ch.queueBind(queueName, exchange, routingKey);
      }

            QueueingConsumer consumer = new QueueingConsumer(ch);
            ch.basicConsume(queueName, consumer);
            while (true) {
                QueueingConsumer.Delivery delivery = consumer.nextDelivery();
    Map<String, Object> headers = delivery.getProperties().getHeaders();
    byte[] body = delivery.getBody();
    Object headerFilenameO = headers.get("filename");
    String headerFilename =
        (headerFilenameO == null)
View Full Code Here

        connectionFactory.setHost(params.host);
        connectionFactory.setPort(params.port);
        connection = connectionFactory.newConnection();
        channel = connection.createChannel();
        channel.basicQos(1);
        QueueingConsumer consumer = new QueueingConsumer(channel);
        try {
            channel.flow(false);
            publish(consume(consumer));
            channel.flow(true);
            return drain(consumer);
View Full Code Here

                Connection conn = connectionFactory.newConnection();
                Channel ch = conn.createChannel();
                ch.queueDeclare(QUEUE_NAME, true, false, false, null);

                // Consume
                QueueingConsumer qc = new QueueingConsumer(ch);
                ch.basicConsume(QUEUE_NAME, true, qc);
                for (int i = 0; i < msgCount; ++i) {
                    qc.nextDelivery();
                }

                // Cleanup
                ch.close();
                conn.close();
View Full Code Here

    // requeue=false.  So we can't really test any scenarios for
    // requeue=false.

    void verifyRedeliverOnRecover(RecoverCallback call)
        throws IOException, InterruptedException {
        QueueingConsumer consumer = new QueueingConsumer(channel);
        channel.basicConsume(queue, false, consumer); // require acks.
        channel.basicPublish("", queue, new AMQP.BasicProperties.Builder().build(), body);
        QueueingConsumer.Delivery delivery = consumer.nextDelivery();
        assertTrue("consumed message body not as sent",
                   Arrays.equals(body, delivery.getBody()));
        // Don't ack it, and get it redelivered to the same consumer
        call.recover(channel);
        QueueingConsumer.Delivery secondDelivery = consumer.nextDelivery(5000);
        assertNotNull("timed out waiting for redelivered message", secondDelivery);
        assertTrue("consumed (redelivered) message body not as sent",
                   Arrays.equals(body, delivery.getBody()));
    }
View Full Code Here

                   Arrays.equals(body, delivery.getBody()));
    }

    void verifyNoRedeliveryWithAutoAck(RecoverCallback call)
        throws IOException, InterruptedException {
        QueueingConsumer consumer = new QueueingConsumer(channel);
        channel.basicConsume(queue, true, consumer); // auto ack.
        channel.basicPublish("", queue, new AMQP.BasicProperties.Builder().build(), body);
        QueueingConsumer.Delivery delivery = consumer.nextDelivery();
        assertTrue("consumed message body not as sent",
                   Arrays.equals(body, delivery.getBody()));
        call.recover(channel);
        // there's a race here between our recover finishing and the basic.get;
        Thread.sleep(500);
View Full Code Here

        }
        for (String[] binding : bindings) {
            channel.queueBind(binding[0], binding[1], "");
        }
        for (int idx = 0; idx < consumers.length; ++idx) {
            QueueingConsumer consumer = new QueueingConsumer(channel);
            channel.basicConsume(queues[idx], true, consumer);
            consumers[idx] = consumer;
        }
    }
View Full Code Here

    public void testNoRequeueOnCancel()
        throws IOException, InterruptedException
    {
        channel.basicPublish("", Q, null, "1".getBytes());

        QueueingConsumer c;

        c = new QueueingConsumer(channel);
        String consumerTag = channel.basicConsume(Q, false, c);
        c.nextDelivery();
        channel.basicCancel(consumerTag);

        assertNull(channel.basicGet(Q, true));

        closeChannel();
View Full Code Here

            long startTime;
            startTime = now = System.currentTimeMillis();
            int totalMsgCount = 0;

            try {
                q = new QueueingConsumer(channel);
                channel.basicConsume(queueName, autoAck, q);

                while (timeLimit == 0 || now < startTime + timeLimit) {
                    Delivery delivery;
                    try {
                        if (timeLimit == 0) {
                            delivery = q.nextDelivery();
                        } else {
                            delivery = q.nextDelivery(startTime + timeLimit - now);
                            if (delivery == null) break;
                        }
                    } catch (ConsumerCancelledException e) {
                        System.out.println("Consumer cancelled by broker. Re-consuming.");
                        q = new QueueingConsumer(channel);
                        channel.basicConsume(queueName, autoAck, q);
                        continue;
                    }
        totalMsgCount++;
View Full Code Here

    public void testFlowControl() throws IOException, InterruptedException {
        basicPublishVolatile(Q);
        setResourceAlarm("memory");
        // non-publish actions only after an alarm should be fine
        assertNotNull(basicGet(Q));
        QueueingConsumer c = new QueueingConsumer(channel);
        String consumerTag = channel.basicConsume(Q, true, c);
        // publishes after an alarm should not go through
        basicPublishVolatile(Q);
        // the publish is async, so this is racy. This also tests we don't die
        // by heartbeat (3x heartbeat interval + epsilon)
        assertNull(c.nextDelivery(3100));
        // once the alarm has cleared the publishes should go through
        clearResourceAlarm("memory");
        assertNotNull(c.nextDelivery());
        // everything should be back to normal
        channel.basicCancel(consumerTag);
        basicPublishVolatile(Q);
        assertNotNull(basicGet(Q));
    }
View Full Code Here

TOP

Related Classes of com.rabbitmq.client.QueueingConsumer$Delivery

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.