Search in sources :

Example 1 with Queue

use of org.springframework.amqp.core.Queue in project tutorials by eugenp.

the class BroadcastConfig method topicBindings.

@Bean
public List<Declarable> topicBindings() {
    Queue topicQueue1 = new Queue(topicQueue1Name, false);
    Queue topicQueue2 = new Queue(topicQueue2Name, false);
    TopicExchange topicExchange = new TopicExchange(topicExchangeName);
    return Arrays.asList(topicQueue1, topicQueue2, topicExchange, BindingBuilder.bind(topicQueue1).to(topicExchange).with("*.important.*"), BindingBuilder.bind(topicQueue2).to(topicExchange).with("user.#"));
}
Also used : Queue(org.springframework.amqp.core.Queue) TopicExchange(org.springframework.amqp.core.TopicExchange) Bean(org.springframework.context.annotation.Bean)

Example 2 with Queue

use of org.springframework.amqp.core.Queue 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 Queue

use of org.springframework.amqp.core.Queue 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 Queue

use of org.springframework.amqp.core.Queue 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)

Example 5 with Queue

use of org.springframework.amqp.core.Queue 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)

Aggregations

Queue (org.springframework.amqp.core.Queue)6 RabbitAdmin (org.springframework.amqp.rabbit.core.RabbitAdmin)4 AmqpTemplate (org.springframework.amqp.core.AmqpTemplate)2 TopicExchange (org.springframework.amqp.core.TopicExchange)2 Bean (org.springframework.context.annotation.Bean)2 Before (org.junit.Before)1 Test (org.junit.Test)1 FanoutExchange (org.springframework.amqp.core.FanoutExchange)1 CachingConnectionFactory (org.springframework.amqp.rabbit.connection.CachingConnectionFactory)1 ConnectionFactory (org.springframework.amqp.rabbit.connection.ConnectionFactory)1 RabbitTemplate (org.springframework.amqp.rabbit.core.RabbitTemplate)1 SimpleMessageListenerContainer (org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer)1 BeanFactory (org.springframework.beans.factory.BeanFactory)1