Search in sources :

Example 1 with Declarables

use of org.springframework.amqp.core.Declarables in project tutorials by jhkim105.

the class AmqpConfig method fanoutBindings.

@Bean
public Declarables fanoutBindings() {
    Queue fanoutQueue1 = new Queue(FANOUT_QUEUE_A, false);
    Queue fanoutQueue2 = new Queue(FANOUT_QUEUE_B, false);
    FanoutExchange fanoutExchange = new FanoutExchange(FANOUT_EXCHANGE);
    return new Declarables(fanoutQueue1, fanoutQueue2, fanoutExchange, BindingBuilder.bind(fanoutQueue1).to(fanoutExchange), BindingBuilder.bind(fanoutQueue2).to(fanoutExchange));
}
Also used : Declarables(org.springframework.amqp.core.Declarables) Queue(org.springframework.amqp.core.Queue) FanoutExchange(org.springframework.amqp.core.FanoutExchange) Bean(org.springframework.context.annotation.Bean)

Example 2 with Declarables

use of org.springframework.amqp.core.Declarables in project tutorials by jhkim105.

the class AmqpConfig method topicBindings.

@Bean
public Declarables topicBindings() {
    Queue topicQueue1 = new Queue(TOPIC_QUEUE_A, false);
    Queue topicQueue2 = new Queue(TOPIC_QUEUE_B, false);
    TopicExchange topicExchange = new TopicExchange(TOPIC_EXCHANGE);
    return new Declarables(topicQueue1, topicQueue2, topicExchange, BindingBuilder.bind(topicQueue1).to(topicExchange).with("*.important.*"), BindingBuilder.bind(topicQueue2).to(topicExchange).with("#.error"));
}
Also used : Declarables(org.springframework.amqp.core.Declarables) Queue(org.springframework.amqp.core.Queue) TopicExchange(org.springframework.amqp.core.TopicExchange) Bean(org.springframework.context.annotation.Bean)

Example 3 with Declarables

use of org.springframework.amqp.core.Declarables in project spring-amqp by spring-projects.

the class RabbitAdminTests method testMultiEntities.

@Test
@LogLevels(classes = RabbitAdmin.class, level = "DEBUG")
public void testMultiEntities() {
    ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext(Config.class);
    RabbitTemplate template = ctx.getBean(RabbitTemplate.class);
    template.convertAndSend("e1", "k1", "foo");
    template.convertAndSend("e2", "k2", "bar");
    template.convertAndSend("e3", "k3", "baz");
    template.convertAndSend("e4", "k4", "qux");
    assertThat(template.receiveAndConvert("q1")).isEqualTo("foo");
    assertThat(template.receiveAndConvert("q2")).isEqualTo("bar");
    assertThat(template.receiveAndConvert("q3")).isEqualTo("baz");
    assertThat(template.receiveAndConvert("q4")).isEqualTo("qux");
    RabbitAdmin admin = ctx.getBean(RabbitAdmin.class);
    admin.deleteQueue("q1");
    admin.deleteQueue("q2");
    admin.deleteQueue("q3");
    admin.deleteQueue("q4");
    admin.deleteExchange("e1");
    admin.deleteExchange("e2");
    admin.deleteExchange("e3");
    admin.deleteExchange("e4");
    assertThat(admin.getQueueProperties(ctx.getBean(Config.class).prototypeQueueName)).isNull();
    Declarables mixedDeclarables = ctx.getBean("ds", Declarables.class);
    assertThat(mixedDeclarables.getDeclarablesByType(Queue.class)).hasSize(1).extracting(Queue::getName).contains("q4");
    assertThat(mixedDeclarables.getDeclarablesByType(Exchange.class)).hasSize(1).extracting(Exchange::getName).contains("e4");
    assertThat(mixedDeclarables.getDeclarablesByType(Binding.class)).hasSize(1).extracting(Binding::getDestination).contains("q4");
    ctx.close();
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) Declarables(org.springframework.amqp.core.Declarables) Test(org.junit.jupiter.api.Test) LogLevels(org.springframework.amqp.rabbit.junit.LogLevels)

Aggregations

Declarables (org.springframework.amqp.core.Declarables)3 Queue (org.springframework.amqp.core.Queue)2 Bean (org.springframework.context.annotation.Bean)2 Test (org.junit.jupiter.api.Test)1 FanoutExchange (org.springframework.amqp.core.FanoutExchange)1 TopicExchange (org.springframework.amqp.core.TopicExchange)1 LogLevels (org.springframework.amqp.rabbit.junit.LogLevels)1 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)1 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)1