Example usage for org.springframework.amqp.core AnonymousQueue getName

List of usage examples for org.springframework.amqp.core AnonymousQueue getName

Introduction

In this page you can find the example usage for org.springframework.amqp.core AnonymousQueue getName.

Prototype

public String getName() 

Source Link

Document

Return the name provided in the constructor.

Usage

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

@Test
public void testListenFromAnonQueue() throws Exception {
    AnonymousQueue queue = new AnonymousQueue();
    CountDownLatch latch = new CountDownLatch(10);
    SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(
            template.getConnectionFactory());
    container.setMessageListener(new MessageListenerAdapter(new PojoListener(latch)));
    container.setQueueNames(queue.getName());
    container.setConcurrentConsumers(2);
    GenericApplicationContext context = new GenericApplicationContext();
    context.getBeanFactory().registerSingleton("foo", queue);
    context.refresh();//from  ww  w . j  a  v a2s.c o m
    container.setApplicationContext(context);
    RabbitAdmin admin = new RabbitAdmin(this.template.getConnectionFactory());
    admin.setApplicationContext(context);
    container.setRabbitAdmin(admin);
    container.afterPropertiesSet();
    container.start();
    for (int i = 0; i < 10; i++) {
        template.convertAndSend(queue.getName(), i + "foo");
    }
    assertTrue(latch.await(10, TimeUnit.SECONDS));
    container.stop();
    container.start();
    latch = new CountDownLatch(10);
    container.setMessageListener(new MessageListenerAdapter(new PojoListener(latch)));
    for (int i = 0; i < 10; i++) {
        template.convertAndSend(queue.getName(), i + "foo");
    }
    assertTrue(latch.await(10, TimeUnit.SECONDS));
    container.stop();
}

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

@Test
public void testAddQueuesAndStartInCycle() throws Exception {
    final SingleConnectionFactory connectionFactory = new SingleConnectionFactory("localhost");
    final SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(connectionFactory);
    container.setMessageListener((MessageListener) message -> {
    });//from w w w .  j a va  2s.c  o m
    container.setConcurrentConsumers(2);
    container.afterPropertiesSet();

    RabbitAdmin admin = new RabbitAdmin(connectionFactory);
    for (int i = 0; i < 20; i++) {
        AnonymousQueue anonymousQueue = new AnonymousQueue();
        admin.declareQueue(anonymousQueue);
        container.addQueueNames(anonymousQueue.getName());
        if (!container.isRunning()) {
            container.start();
        }
    }

    int n = 0;
    while (n++ < 100 && container.getActiveConsumerCount() != 2) {
        Thread.sleep(100);
    }
    assertEquals(2, container.getActiveConsumerCount());
    container.stop();
    connectionFactory.destroy();
}