Example usage for org.springframework.amqp.rabbit.core RabbitAdmin QUEUE_CONSUMER_COUNT

List of usage examples for org.springframework.amqp.rabbit.core RabbitAdmin QUEUE_CONSUMER_COUNT

Introduction

In this page you can find the example usage for org.springframework.amqp.rabbit.core RabbitAdmin QUEUE_CONSUMER_COUNT.

Prototype

Object QUEUE_CONSUMER_COUNT

To view the source code for org.springframework.amqp.rabbit.core RabbitAdmin QUEUE_CONSUMER_COUNT.

Click Source Link

Document

Property key for the consumer count in the Properties returned by #getQueueProperties(String) .

Usage

From source file:org.springframework.amqp.rabbit.core.RabbitAdminTests.java

@Test
public void testProperties() throws Exception {
    SingleConnectionFactory connectionFactory = new SingleConnectionFactory();
    connectionFactory.setHost("localhost");
    RabbitAdmin rabbitAdmin = new RabbitAdmin(connectionFactory);
    String queueName = "test.properties." + System.currentTimeMillis();
    try {/*from w w  w.  j ava 2 s .  com*/
        rabbitAdmin.declareQueue(new Queue(queueName));
        new RabbitTemplate(connectionFactory).convertAndSend(queueName, "foo");
        int n = 0;
        while (n++ < 100 && messageCount(rabbitAdmin, queueName) == 0) {
            Thread.sleep(100);
        }
        assertTrue("Message count = 0", n < 100);
        Channel channel = connectionFactory.createConnection().createChannel(false);
        DefaultConsumer consumer = new DefaultConsumer(channel);
        channel.basicConsume(queueName, true, consumer);
        n = 0;
        while (n++ < 100 && messageCount(rabbitAdmin, queueName) > 0) {
            Thread.sleep(100);
        }
        assertTrue("Message count > 0", n < 100);
        Properties props = rabbitAdmin.getQueueProperties(queueName);
        assertNotNull(props.get(RabbitAdmin.QUEUE_CONSUMER_COUNT));
        assertEquals(1, props.get(RabbitAdmin.QUEUE_CONSUMER_COUNT));
        channel.close();
    } finally {
        rabbitAdmin.deleteQueue(queueName);
        connectionFactory.destroy();
    }
}

From source file:org.springframework.amqp.rabbit.listener.DirectMessageListenerContainerIntegrationTests.java

private boolean consumersOnQueue(String queue, int expected) throws Exception {
    int n = 0;//from www  . ja  va  2  s.com
    Properties queueProperties = admin.getQueueProperties(queue);
    LogFactory.getLog(getClass()).debug(queue + " waiting for " + expected + " : " + queueProperties);
    while (n++ < 600 && (queueProperties == null
            || !queueProperties.get(RabbitAdmin.QUEUE_CONSUMER_COUNT).equals(expected))) {
        Thread.sleep(100);
        queueProperties = admin.getQueueProperties(queue);
        LogFactory.getLog(getClass()).debug(queue + " waiting for " + expected + " : " + queueProperties);
    }
    return queueProperties.get(RabbitAdmin.QUEUE_CONSUMER_COUNT).equals(expected);
}

From source file:org.springframework.amqp.rabbit.listener.DirectMessageListenerContainerTests.java

private boolean consumersOnQueue(String queue, int expected) throws Exception {
    int n = 0;/*from   w  w  w  .j  av a 2 s.  c om*/
    RabbitAdmin admin = brokerRunning.getAdmin();
    Properties queueProperties = admin.getQueueProperties(queue);
    LogFactory.getLog(getClass()).debug(queue + " waiting for " + expected + " : " + queueProperties);
    while (n++ < 600 && (queueProperties == null
            || !queueProperties.get(RabbitAdmin.QUEUE_CONSUMER_COUNT).equals(expected))) {
        Thread.sleep(100);
        queueProperties = admin.getQueueProperties(queue);
        LogFactory.getLog(getClass()).debug(queue + " waiting for " + expected + " : " + queueProperties);
    }
    return queueProperties.get(RabbitAdmin.QUEUE_CONSUMER_COUNT).equals(expected);
}