Search in sources :

Example 6 with RabbitAdmin

use of org.springframework.amqp.rabbit.core.RabbitAdmin in project spring-integration by spring-projects.

the class ChannelTests method channelDeclarationTests.

/*
	 * Verify queue is declared if not present and not declared if it is already present.
	 */
@Test
public void channelDeclarationTests() {
    RabbitAdmin admin = new RabbitAdmin(this.connectionFactory);
    admin.deleteQueue("implicit");
    SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(this.connectionFactory);
    container.setAutoStartup(false);
    AmqpTemplate amqpTemplate = mock(AmqpTemplate.class);
    PointToPointSubscribableAmqpChannel channel = new PointToPointSubscribableAmqpChannel("implicit", container, amqpTemplate);
    channel.setBeanFactory(mock(BeanFactory.class));
    channel.afterPropertiesSet();
    channel.onCreate(null);
    assertNotNull(admin.getQueueProperties("implicit"));
    admin.deleteQueue("explicit");
    channel.setQueueName("explicit");
    channel.afterPropertiesSet();
    channel.onCreate(null);
    assertNotNull(admin.getQueueProperties("explicit"));
    admin.deleteQueue("explicit");
    // verify no declaration if exists with non-standard props
    admin.declareQueue(new Queue("explicit", false));
    channel.afterPropertiesSet();
    channel.onCreate(null);
    assertNotNull(admin.getQueueProperties("explicit"));
    admin.deleteQueue("explicit");
}
Also used : SimpleMessageListenerContainer(org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer) BeanFactory(org.springframework.beans.factory.BeanFactory) RabbitAdmin(org.springframework.amqp.rabbit.core.RabbitAdmin) Queue(org.springframework.amqp.core.Queue) AmqpTemplate(org.springframework.amqp.core.AmqpTemplate) Test(org.junit.Test)

Example 7 with RabbitAdmin

use of org.springframework.amqp.rabbit.core.RabbitAdmin in project spring-integration by spring-projects.

the class ChannelTests method testAmqpChannelFactoryBean.

@Test
public void testAmqpChannelFactoryBean() throws Exception {
    AmqpChannelFactoryBean channelFactoryBean = new AmqpChannelFactoryBean();
    channelFactoryBean.setBeanFactory(mock(BeanFactory.class));
    channelFactoryBean.setConnectionFactory(this.connectionFactory);
    channelFactoryBean.setBeanName("testChannel");
    channelFactoryBean.afterPropertiesSet();
    AbstractAmqpChannel channel = channelFactoryBean.getObject();
    assertThat(channel, instanceOf(PointToPointSubscribableAmqpChannel.class));
    channelFactoryBean = new AmqpChannelFactoryBean();
    channelFactoryBean.setBeanFactory(mock(BeanFactory.class));
    channelFactoryBean.setConnectionFactory(this.connectionFactory);
    channelFactoryBean.setBeanName("testChannel");
    channelFactoryBean.setPubSub(true);
    channelFactoryBean.afterPropertiesSet();
    channel = channelFactoryBean.getObject();
    assertThat(channel, instanceOf(PublishSubscribeAmqpChannel.class));
    RabbitAdmin rabbitAdmin = new RabbitAdmin(this.connectionFactory);
    rabbitAdmin.deleteQueue("testChannel");
    rabbitAdmin.deleteExchange("si.fanout.testChannel");
}
Also used : BeanFactory(org.springframework.beans.factory.BeanFactory) RabbitAdmin(org.springframework.amqp.rabbit.core.RabbitAdmin) AmqpChannelFactoryBean(org.springframework.integration.amqp.config.AmqpChannelFactoryBean) Test(org.junit.Test)

Aggregations

RabbitAdmin (org.springframework.amqp.rabbit.core.RabbitAdmin)7 Queue (org.springframework.amqp.core.Queue)4 Test (org.junit.Test)3 AmqpTemplate (org.springframework.amqp.core.AmqpTemplate)2 CachingConnectionFactory (org.springframework.amqp.rabbit.connection.CachingConnectionFactory)2 RabbitTemplate (org.springframework.amqp.rabbit.core.RabbitTemplate)2 BeanFactory (org.springframework.beans.factory.BeanFactory)2 Before (org.junit.Before)1 TopicExchange (org.springframework.amqp.core.TopicExchange)1 ConnectionFactory (org.springframework.amqp.rabbit.connection.ConnectionFactory)1 RabbitMessagingTemplate (org.springframework.amqp.rabbit.core.RabbitMessagingTemplate)1 SimpleMessageListenerContainer (org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer)1 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)1 AbstractApplicationContext (org.springframework.context.support.AbstractApplicationContext)1 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)1 AmqpChannelFactoryBean (org.springframework.integration.amqp.config.AmqpChannelFactoryBean)1