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

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

Introduction

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

Prototype

@Override
public void afterPropertiesSet() 

Source Link

Document

If #setAutoStartup(boolean) autoStartup is set to true, registers a callback on the ConnectionFactory to declare all exchanges and queues in the enclosing application context.

Usage

From source file:org.springframework.cloud.netflix.hystrix.amqp.HystrixStreamAutoConfiguration.java

private ConnectionFactory connectionFactory() {
    if (this.hystrixConnectionFactory != null) {
        RabbitAdmin amqpAdmin = new RabbitAdmin(this.hystrixConnectionFactory);
        hystrixStreamExchange().setAdminsThatShouldDeclare(amqpAdmin);
        amqpAdmin.setApplicationContext(this.context);
        amqpAdmin.afterPropertiesSet();
        return this.hystrixConnectionFactory;
    }/*from w  ww.j  a  v  a2 s  .co m*/
    return this.primaryConnectionFactory;
}

From source file:org.springframework.cloud.netflix.turbine.amqp.TurbineAmqpAutoConfiguration.java

private ConnectionFactory connectionFactory() {
    if (this.turbineConnectionFactory != null) {
        RabbitAdmin amqpAdmin = new RabbitAdmin(this.turbineConnectionFactory);
        hystrixStreamExchange().setAdminsThatShouldDeclare(amqpAdmin);
        localTurbineAmqpQueueBinding().setAdminsThatShouldDeclare(amqpAdmin);
        hystrixStreamQueue().setAdminsThatShouldDeclare(amqpAdmin);
        amqpAdmin.setApplicationContext(this.context);
        amqpAdmin.afterPropertiesSet();
        return this.turbineConnectionFactory;
    }/*from   w  w  w. j a  va  2  s.co  m*/
    return this.primaryConnectionFactory;
}

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

@Test
public void testNoFailOnStartupWithMissingBroker() throws Exception {
    SingleConnectionFactory connectionFactory = new SingleConnectionFactory("foo");
    connectionFactory.setPort(434343);// w  w  w . j a v a  2s.  c  o  m
    GenericApplicationContext applicationContext = new GenericApplicationContext();
    applicationContext.getBeanFactory().registerSingleton("foo", new Queue("queue"));
    RabbitAdmin rabbitAdmin = new RabbitAdmin(connectionFactory);
    rabbitAdmin.setApplicationContext(applicationContext);
    rabbitAdmin.setAutoStartup(true);
    rabbitAdmin.afterPropertiesSet();
    connectionFactory.destroy();
}

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

@Test
public void testFailOnFirstUseWithMissingBroker() throws Exception {
    SingleConnectionFactory connectionFactory = new SingleConnectionFactory("localhost");
    connectionFactory.setPort(434343);//from   w  ww.java2 s .  co m
    GenericApplicationContext applicationContext = new GenericApplicationContext();
    applicationContext.getBeanFactory().registerSingleton("foo", new Queue("queue"));
    RabbitAdmin rabbitAdmin = new RabbitAdmin(connectionFactory);
    rabbitAdmin.setApplicationContext(applicationContext);
    rabbitAdmin.setAutoStartup(true);
    rabbitAdmin.afterPropertiesSet();
    exception.expect(IllegalArgumentException.class);
    rabbitAdmin.declareQueue();
    connectionFactory.destroy();
}

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

@Test
public void testTemporaryLogs() throws Exception {
    SingleConnectionFactory connectionFactory = new SingleConnectionFactory();
    connectionFactory.setHost("localhost");
    RabbitAdmin rabbitAdmin = new RabbitAdmin(connectionFactory);
    try {/*w  ww  .  j  av  a 2 s .  c o  m*/
        ApplicationContext ctx = mock(ApplicationContext.class);
        Map<String, Queue> queues = new HashMap<String, Queue>();
        queues.put("nonDurQ", new Queue("testq.nonDur", false, false, false));
        queues.put("adQ", new Queue("testq.ad", true, false, true));
        queues.put("exclQ", new Queue("testq.excl", true, true, false));
        queues.put("allQ", new Queue("testq.all", false, true, true));
        when(ctx.getBeansOfType(Queue.class)).thenReturn(queues);
        Map<String, Exchange> exchanges = new HashMap<String, Exchange>();
        exchanges.put("nonDurEx", new DirectExchange("testex.nonDur", false, false));
        exchanges.put("adEx", new DirectExchange("testex.ad", true, true));
        exchanges.put("allEx", new DirectExchange("testex.all", false, true));
        when(ctx.getBeansOfType(Exchange.class)).thenReturn(exchanges);
        rabbitAdmin.setApplicationContext(ctx);
        rabbitAdmin.afterPropertiesSet();
        Log logger = spy(TestUtils.getPropertyValue(rabbitAdmin, "logger", Log.class));
        doReturn(true).when(logger).isInfoEnabled();
        doAnswer(new DoesNothing()).when(logger).info(anyString());
        new DirectFieldAccessor(rabbitAdmin).setPropertyValue("logger", logger);
        connectionFactory.createConnection().close(); // force declarations
        ArgumentCaptor<String> log = ArgumentCaptor.forClass(String.class);
        verify(logger, times(7)).info(log.capture());
        List<String> logs = log.getAllValues();
        Collections.sort(logs);
        assertThat(logs.get(0), Matchers.containsString("(testex.ad) durable:true, auto-delete:true"));
        assertThat(logs.get(1), Matchers.containsString("(testex.all) durable:false, auto-delete:true"));
        assertThat(logs.get(2), Matchers.containsString("(testex.nonDur) durable:false, auto-delete:false"));
        assertThat(logs.get(3),
                Matchers.containsString("(testq.ad) durable:true, auto-delete:true, exclusive:false"));
        assertThat(logs.get(4),
                Matchers.containsString("(testq.all) durable:false, auto-delete:true, exclusive:true"));
        assertThat(logs.get(5),
                Matchers.containsString("(testq.excl) durable:true, auto-delete:false, exclusive:true"));
        assertThat(logs.get(6),
                Matchers.containsString("(testq.nonDur) durable:false, auto-delete:false, exclusive:false"));
    } finally {
        cleanQueuesAndExchanges(rabbitAdmin);
        connectionFactory.destroy();
    }
}