Search in sources :

Example 1 with RabbitAdmin

use of org.springframework.amqp.rabbit.core.RabbitAdmin in project microservices by pwillhan.

the class RabbitAdminSpringExample method main.

public static void main(String[] args) {
    AbstractApplicationContext context = new ClassPathXmlApplicationContext("configuration.xml");
    RabbitAdmin admin = context.getBean(RabbitAdmin.class);
}
Also used : AbstractApplicationContext(org.springframework.context.support.AbstractApplicationContext) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) RabbitAdmin(org.springframework.amqp.rabbit.core.RabbitAdmin)

Example 2 with RabbitAdmin

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

the class AmqpMessageSourceIntegrationTests method before.

@Before
public void before() {
    RabbitAdmin admin = new RabbitAdmin(this.config.connectionFactory());
    Queue queue = QueueBuilder.nonDurable(QUEUE_WITH_DLQ).autoDelete().withArgument("x-dead-letter-exchange", "").withArgument("x-dead-letter-routing-key", DLQ).build();
    admin.declareQueue(queue);
    this.context.start();
}
Also used : RabbitAdmin(org.springframework.amqp.rabbit.core.RabbitAdmin) Queue(org.springframework.amqp.core.Queue) Before(org.junit.Before)

Example 3 with RabbitAdmin

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

the class PollableAmqpChannel method onInit.

@Override
protected void onInit() throws Exception {
    AmqpTemplate amqpTemplate = getAmqpTemplate();
    if (this.queue == null) {
        if (getAdmin() == null && amqpTemplate instanceof RabbitTemplate) {
            ConnectionFactory connectionFactory = ((RabbitTemplate) amqpTemplate).getConnectionFactory();
            setAdmin(new RabbitAdmin(connectionFactory));
            setConnectionFactory(connectionFactory);
        }
        Assert.notNull(getAdmin(), "If no queueName is configured explicitly, an AmqpAdmin instance must be provided, " + "or the AmqpTemplate must be a RabbitTemplate since the Queue needs to be declared.");
        this.queue = new Queue(this.channelName);
    }
    super.onInit();
}
Also used : RabbitTemplate(org.springframework.amqp.rabbit.core.RabbitTemplate) ConnectionFactory(org.springframework.amqp.rabbit.connection.ConnectionFactory) RabbitAdmin(org.springframework.amqp.rabbit.core.RabbitAdmin) Queue(org.springframework.amqp.core.Queue) AmqpTemplate(org.springframework.amqp.core.AmqpTemplate)

Example 4 with RabbitAdmin

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

the class RabbitAutoConfigurationTests method testDefaultRabbitConfiguration.

@Test
public void testDefaultRabbitConfiguration() {
    load(TestConfiguration.class);
    RabbitTemplate rabbitTemplate = this.context.getBean(RabbitTemplate.class);
    RabbitMessagingTemplate messagingTemplate = this.context.getBean(RabbitMessagingTemplate.class);
    CachingConnectionFactory connectionFactory = this.context.getBean(CachingConnectionFactory.class);
    DirectFieldAccessor dfa = new DirectFieldAccessor(connectionFactory);
    RabbitAdmin amqpAdmin = this.context.getBean(RabbitAdmin.class);
    assertThat(rabbitTemplate.getConnectionFactory()).isEqualTo(connectionFactory);
    assertThat(getMandatory(rabbitTemplate)).isFalse();
    assertThat(messagingTemplate.getRabbitTemplate()).isEqualTo(rabbitTemplate);
    assertThat(amqpAdmin).isNotNull();
    assertThat(connectionFactory.getHost()).isEqualTo("localhost");
    assertThat(dfa.getPropertyValue("publisherConfirms")).isEqualTo(false);
    assertThat(dfa.getPropertyValue("publisherReturns")).isEqualTo(false);
    assertThat(this.context.containsBean("rabbitListenerContainerFactory")).as("Listener container factory should be created by default").isTrue();
}
Also used : RabbitTemplate(org.springframework.amqp.rabbit.core.RabbitTemplate) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) RabbitMessagingTemplate(org.springframework.amqp.rabbit.core.RabbitMessagingTemplate) CachingConnectionFactory(org.springframework.amqp.rabbit.connection.CachingConnectionFactory) RabbitAdmin(org.springframework.amqp.rabbit.core.RabbitAdmin) Test(org.junit.Test)

Example 5 with RabbitAdmin

use of org.springframework.amqp.rabbit.core.RabbitAdmin in project microservices by pwillhan.

the class RabbitAdminExample method main.

public static void main(String[] args) {
    CachingConnectionFactory factory = new CachingConnectionFactory("localhost");
    RabbitAdmin admin = new RabbitAdmin(factory);
    Queue queue = new Queue("test-queue");
    admin.declareQueue(queue);
    TopicExchange exchange = new TopicExchange("sample-topic-exchange");
    admin.declareExchange(exchange);
    admin.declareBinding(BindingBuilder.bind(queue).to(exchange).with("sample-key"));
    factory.destroy();
}
Also used : CachingConnectionFactory(org.springframework.amqp.rabbit.connection.CachingConnectionFactory) RabbitAdmin(org.springframework.amqp.rabbit.core.RabbitAdmin) Queue(org.springframework.amqp.core.Queue) TopicExchange(org.springframework.amqp.core.TopicExchange)

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