Package com.rabbitmq.client

Examples of com.rabbitmq.client.QueueingConsumer


        assertNotNull(basicGet(Q));
    }


    public void testOverlappingAlarmsFlowControl() throws IOException, InterruptedException {
        QueueingConsumer c = new QueueingConsumer(channel);
        String consumerTag = channel.basicConsume(Q, true, c);

        setResourceAlarm("memory");
        basicPublishVolatile(Q);

        assertNull(c.nextDelivery(100));
        setResourceAlarm("disk");
        assertNull(c.nextDelivery(100));
        clearResourceAlarm("memory");
        assertNull(c.nextDelivery(100));
        clearResourceAlarm("disk");
        assertNotNull(c.nextDelivery());

        channel.basicCancel(consumerTag);
        basicPublishVolatile(Q);
        assertNotNull(basicGet(Q));
    }
View Full Code Here


    public void testConsumerCancellationNotification() throws IOException,
            InterruptedException {
        final BlockingQueue<Boolean> result = new ArrayBlockingQueue<Boolean>(1);

        channel.queueDeclare(queue, false, true, false, null);
        Consumer consumer = new QueueingConsumer(channel) {
            @Override
            public void handleCancel(String consumerTag) throws IOException {
                try {
                    result.put(true);
                } catch (InterruptedException e) {
View Full Code Here

    public void testConsumerCancellationInterruptsQueuingConsumerWait()
            throws IOException, InterruptedException {
        final BlockingQueue<Boolean> result = new ArrayBlockingQueue<Boolean>(1);
        channel.queueDeclare(queue, false, true, false, null);
        final QueueingConsumer consumer = new QueueingConsumer(channel);
        Runnable receiver = new Runnable() {

            public void run() {
                try {
                    try {
                        consumer.nextDelivery();
                    } catch (ConsumerCancelledException e) {
                        result.put(true);
                        return;
                    } catch (ShutdownSignalException e) {
                    } catch (InterruptedException e) {
View Full Code Here

        basicPublishVolatile(m1, q);
        basicPublishVolatile(m2, q);

        long tag1 = checkDelivery(channel.basicGet(q, false), m1, false);
        long tag2 = checkDelivery(channel.basicGet(q, false), m2, false);
        QueueingConsumer c = new QueueingConsumer(secondaryChannel);
        String consumerTag = secondaryChannel.basicConsume(q, false, c);
        channel.basicReject(tag2, true);
        long tag3 = checkDelivery(c.nextDelivery(), m2, true);
        secondaryChannel.basicCancel(consumerTag);
        secondaryChannel.basicReject(tag3, false);
        assertNull(channel.basicGet(q, false));
        channel.basicAck(tag1, false);
        channel.basicReject(tag3, false);
View Full Code Here

      queueNames = new String[j];
      for (int i = 0; i < j; i++) {
        queueNames[i] = randomString();
        channel.queueDeclare(queueNames[i], durable, false, false, null);
        channel.queueBind(queueNames[i], binding.x, binding.k);
        channel.basicConsume(queueNames[i], true, new QueueingConsumer(channel));
      }
    }
    subscribeSendUnsubscribe(binding);
    if (durable) {
      restart();
    }
    if (queues > 1) {
      for (String s : queueNames) {
        channel.basicConsume(s, true, new QueueingConsumer(channel));
        Binding tmp = new Binding(s, binding.x, binding.k);
        sendUnroutable(tmp);
      }
    }
    channel.queueDeclare(binding.q, durable, true, true, null);
View Full Code Here

    createQueueAndBindToExchange(binding, durable);
    return binding;
  }

  protected void subscribeSendUnsubscribe(Binding binding) throws IOException {
    String tag = channel.basicConsume(binding.q, new QueueingConsumer(channel));
    sendUnroutable(binding);
    channel.basicCancel(tag);
  }
View Full Code Here

    public void testConsume()
        throws IOException
    {
        runTest(false, false, true, false, new WithName() {
                public void with(String name) throws IOException {
                    channel.basicConsume(name, new QueueingConsumer(channel));
                }});
    }
View Full Code Here

        redeclare(q, chan);

        trace("Beginning plateau of " + repeatCount + " repeats, sampling every " + sampleGranularity + " messages");

        QueueingConsumer consumer = new QueueingConsumer(chan);
        chan.basicConsume(q, consumer);

        long startTime = System.currentTimeMillis();
        for (int i = 0; i < repeatCount; i++) {
            if (((i % sampleGranularity) == 0) && (i > 0)) {
                long now = System.currentTimeMillis();
                double delta = 1000 * (now - startTime) / (double) sampleGranularity;
                plateauSampleTimes.add(now);
                plateauSampleDeltas.add(delta);
                System.out.print(String.format("# %3d%%; %012d --> %g microseconds/roundtrip            \r",
                                    (100 * i / repeatCount),
                                    now,
                                    delta));
                startTime = System.currentTimeMillis();
            }
            chan.basicPublish("", q, props, body);
            QueueingConsumer.Delivery d = consumer.nextDelivery();
            chan.basicAck(d.getEnvelope().getDeliveryTag(), false);
        }
        System.out.println();

        trace("Switching QOS to unlimited");
        chan.basicQos(0);

        trace("Draining backlog");
        for (int i = 0; i < backlogSize; i++) {
            QueueingConsumer.Delivery d = consumer.nextDelivery();
            chan.basicAck(d.getEnvelope().getDeliveryTag(), false);
        }

        redeclare(q, chan);

View Full Code Here

    /*
     * Test expiry of requeued messages after being consumed instantly
     */
    public void testExpiryWithRequeueAfterConsume() throws Exception {
        declareAndBindQueue(100);
        QueueingConsumer c = new QueueingConsumer(channel);
        channel.basicConsume(TTL_QUEUE_NAME, c);

        publish(MSG[0]);
        assertNotNull(c.nextDelivery(100));

        closeChannel();
        Thread.sleep(150);
        openChannel();

View Full Code Here

        // when there is no consumer, message should expire
        publish(MSG[0]);
        assertNull(get());

        // when there is a consumer, message should be delivered
        QueueingConsumer c = new QueueingConsumer(channel);
        channel.basicConsume(TTL_QUEUE_NAME, c);
        publish(MSG[0]);
        Delivery d = c.nextDelivery(100);
        assertNotNull(d);

        // requeued messages should expire
        channel.basicReject(d.getEnvelope().getDeliveryTag(), true);
        assertNull(c.nextDelivery(100));
    }
View Full Code Here

TOP

Related Classes of com.rabbitmq.client.QueueingConsumer

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.