Example usage for org.springframework.amqp.core Queue getName

List of usage examples for org.springframework.amqp.core Queue getName

Introduction

In this page you can find the example usage for org.springframework.amqp.core Queue getName.

Prototype

public String getName() 

Source Link

Document

Return the name provided in the constructor.

Usage

From source file:org.springframework.integration.amqp.rule.BrokerRunning.java

@Override
public Statement apply(Statement base, Description description) {
    CachingConnectionFactory connectionFactory = new CachingConnectionFactory();
    connectionFactory.setHost("localhost");

    try {/* w ww .j a v a  2 s  .  com*/

        connectionFactory.setPort(PORT);

        RabbitAdmin admin = new RabbitAdmin(connectionFactory);

        for (Queue queue : queues) {
            String queueName = queue.getName();
            logger.info("Deleting queue: " + queueName);
            // Delete completely - gets rid of consumers and bindings as well
            admin.deleteQueue(queueName);

            if (!DEFAULT_QUEUE_NAME.getName().equals(queueName)) {
                admin.declareQueue(queue);
            }
        }

    } catch (final Exception e) {
        logger.warn("Not executing tests because basic connectivity test failed", e);
        Assume.assumeNoException(e);
    } finally {
        connectionFactory.destroy();
    }

    return super.apply(base, description);
}

From source file:org.springframework.integration.x.rabbit.RabbitMessageBus.java

@Override
public void bindPubSubConsumer(String name, MessageChannel moduleInputChannel) {
    FanoutExchange exchange = new FanoutExchange("topic." + name);
    rabbitAdmin.declareExchange(exchange);
    Queue queue = new AnonymousQueue();
    this.rabbitAdmin.declareQueue(queue);
    org.springframework.amqp.core.Binding binding = BindingBuilder.bind(queue).to(exchange);
    this.rabbitAdmin.declareBinding(binding);
    // register with context so they will be redeclared after a connection failure
    this.autoDeclareContext.getBeanFactory().registerSingleton(queue.getName(), queue);
    if (!autoDeclareContext.containsBean(exchange.getName() + ".binding")) {
        this.autoDeclareContext.getBeanFactory().registerSingleton(exchange.getName() + ".binding", binding);
    }/*w  ww.  jav  a2  s  .c  o m*/
    doRegisterConsumer(name, moduleInputChannel, queue);
}

From source file:org.springframework.xd.dirt.integration.rabbit.RabbitMessageBus.java

@Override
public void bindPubSubConsumer(String name, MessageChannel moduleInputChannel, Properties properties) {
    if (logger.isInfoEnabled()) {
        logger.info("declaring pubsub for inbound: " + name);
    }//w  w w  .  j  a  va2 s . c o  m
    RabbitPropertiesAccessor accessor = new RabbitPropertiesAccessor(properties);
    validateConsumerProperties(name, properties, SUPPORTED_PUBSUB_CONSUMER_PROPERTIES);
    String prefix = accessor.getPrefix(this.defaultPrefix);
    FanoutExchange exchange = new FanoutExchange(prefix + "topic." + name);
    declareExchangeIfNotPresent(exchange);
    String uniqueName = name + "." + UUID.randomUUID().toString();
    Queue queue = new Queue(prefix + uniqueName, false, true, true);
    declareQueueIfNotPresent(queue);
    org.springframework.amqp.core.Binding binding = BindingBuilder.bind(queue).to(exchange);
    this.rabbitAdmin.declareBinding(binding);
    // register with context so they will be redeclared after a connection failure
    this.autoDeclareContext.getBeanFactory().registerSingleton(queue.getName(), queue);
    String bindingBeanName = exchange.getName() + "." + queue.getName() + ".binding";
    if (!autoDeclareContext.containsBean(bindingBeanName)) {
        this.autoDeclareContext.getBeanFactory().registerSingleton(bindingBeanName, binding);
    }
    doRegisterConsumer(name, moduleInputChannel, queue, accessor, true);
    autoBindDLQ(uniqueName, accessor);
}

From source file:org.springframework.xd.dirt.integration.rabbit.RabbitMessageBus.java

private void doRegisterConsumer(String name, MessageChannel moduleInputChannel, Queue queue,
        RabbitPropertiesAccessor properties, boolean isPubSub) {
    // Fix for XD-2503
    // Temporarily overrides the thread context classloader with the one where the SimpleMessageListenerContainer is defined
    // This allows for the proxying that happens while initializing the SimpleMessageListenerContainer to work correctly
    ClassLoader originalClassloader = Thread.currentThread().getContextClassLoader();
    try {/* w  w w  .j  a  v a2  s. c o m*/
        ClassUtils.overrideThreadContextClassLoader(SimpleMessageListenerContainer.class.getClassLoader());
        SimpleMessageListenerContainer listenerContainer = new SimpleMessageListenerContainer(
                this.connectionFactory);
        listenerContainer.setAcknowledgeMode(properties.getAcknowledgeMode(this.defaultAcknowledgeMode));
        listenerContainer.setChannelTransacted(properties.getTransacted(this.defaultChannelTransacted));
        listenerContainer
                .setDefaultRequeueRejected(properties.getRequeueRejected(this.defaultDefaultRequeueRejected));
        if (!isPubSub) {
            int concurrency = properties.getConcurrency(this.defaultConcurrency);
            concurrency = concurrency > 0 ? concurrency : 1;
            listenerContainer.setConcurrentConsumers(concurrency);
            int maxConcurrency = properties.getMaxConcurrency(this.defaultMaxConcurrency);
            if (maxConcurrency > concurrency) {
                listenerContainer.setMaxConcurrentConsumers(maxConcurrency);
            }
        }
        listenerContainer.setPrefetchCount(properties.getPrefetchCount(this.defaultPrefetchCount));
        listenerContainer.setTxSize(properties.getTxSize(this.defaultTxSize));
        listenerContainer.setTaskExecutor(new SimpleAsyncTaskExecutor(queue.getName() + "-"));
        listenerContainer.setQueues(queue);
        int maxAttempts = properties.getMaxAttempts(this.defaultMaxAttempts);
        if (maxAttempts > 1) {
            RetryOperationsInterceptor retryInterceptor = RetryInterceptorBuilder.stateless()
                    .maxAttempts(maxAttempts)
                    .backOffOptions(properties.getBackOffInitialInterval(this.defaultBackOffInitialInterval),
                            properties.getBackOffMultiplier(this.defaultBackOffMultiplier),
                            properties.getBackOffMaxInterval(this.defaultBackOffMaxInterval))
                    .recoverer(new RejectAndDontRequeueRecoverer()).build();
            listenerContainer.setAdviceChain(new Advice[] { retryInterceptor });
        }
        listenerContainer.setAfterReceivePostProcessors(this.decompressingPostProcessor);
        listenerContainer.setMessagePropertiesConverter(RabbitMessageBus.inboundMessagePropertiesConverter);
        listenerContainer.afterPropertiesSet();
        AmqpInboundChannelAdapter adapter = new AmqpInboundChannelAdapter(listenerContainer);
        adapter.setBeanFactory(this.getBeanFactory());
        DirectChannel bridgeToModuleChannel = new DirectChannel();
        bridgeToModuleChannel.setBeanFactory(this.getBeanFactory());
        bridgeToModuleChannel.setBeanName(name + ".bridge");
        adapter.setOutputChannel(bridgeToModuleChannel);
        adapter.setBeanName("inbound." + name);
        DefaultAmqpHeaderMapper mapper = new DefaultAmqpHeaderMapper();
        mapper.setRequestHeaderNames(properties.getRequestHeaderPattens(this.defaultRequestHeaderPatterns));
        mapper.setReplyHeaderNames(properties.getReplyHeaderPattens(this.defaultReplyHeaderPatterns));
        adapter.setHeaderMapper(mapper);
        adapter.afterPropertiesSet();
        Binding consumerBinding = Binding.forConsumer(name, adapter, moduleInputChannel, properties);
        addBinding(consumerBinding);
        ReceivingHandler convertingBridge = new ReceivingHandler();
        convertingBridge.setOutputChannel(moduleInputChannel);
        convertingBridge.setBeanName(name + ".convert.bridge");
        convertingBridge.afterPropertiesSet();
        bridgeToModuleChannel.subscribe(convertingBridge);
        consumerBinding.start();
    } finally {
        Thread.currentThread().setContextClassLoader(originalClassloader);
    }
}

From source file:org.springframework.xd.dirt.integration.rabbit.RabbitMessageBus.java

/**
 * Try passive declaration first, in case the user has pre-configured the queue with
 * incompatible arguments./*from w  w w . j a v a2s  .c  o  m*/
 * @param queue The queue.
 */
private void declareQueueIfNotPresent(Queue queue) {
    if (this.rabbitAdmin.getQueueProperties(queue.getName()) == null) {
        this.rabbitAdmin.declareQueue(queue);
    }
}