Example usage for org.springframework.amqp.core BindingBuilder bind

List of usage examples for org.springframework.amqp.core BindingBuilder bind

Introduction

In this page you can find the example usage for org.springframework.amqp.core BindingBuilder bind.

Prototype

public static DestinationConfigurer bind(Exchange exchange) 

Source Link

Usage

From source file:org.openbaton.nse.api.EventReceiver.java

@Bean
public Binding setCreationBinding(@Qualifier("getCreationQueue") Queue queue, TopicExchange topicExchange) {
    logger.debug("Created Binding for NSR Creation event");
    return BindingBuilder.bind(queue).to(topicExchange).with("ns-creation");
}

From source file:org.openbaton.nse.api.EventReceiver.java

@Bean
public Binding setErrorBinding(@Qualifier("getErrorQueue") Queue queue, TopicExchange topicExchange) {
    logger.debug("Created Binding for NSR error event");
    return BindingBuilder.bind(queue).to(topicExchange).with("ns-error");
}

From source file:org.openbaton.nse.api.EventReceiver.java

@Bean
public Binding setScaleBinding(@Qualifier("getScaleQueue") Queue queue, TopicExchange topicExchange) {
    logger.debug("Created Binding for NSR scale event");
    return BindingBuilder.bind(queue).to(topicExchange).with("ns-scale");
}

From source file:org.opentestsystem.delivery.logging.RabbitConfiguration.java

@Bean
public Binding binding(final TopicExchange topicExchange, final Queue queue) {
    return BindingBuilder.bind(queue).to(topicExchange).with("#");
}

From source file:org.springframework.amqp.rabbit.log4j.web.controller.LogsController.java

@RequestMapping(value = "/binding", method = RequestMethod.POST)
@ResponseBody/*from w w  w .j ava 2s. c  o m*/
public Binding addBinding(@RequestParam String routingKey) {
    try {
        admin.removeBinding(binding);
        Binding binding = BindingBuilder.bind(logQueue).to(exchange).with(routingKey);
        admin.declareBinding(binding);
        this.binding = binding;
    } catch (RuntimeException e) {
        // TODO: create a new BindingResult object to carry back error message
        logger.error("Failed to declare queue or bind it with exchage", e);
    }

    return this.binding;
}

From source file:org.springframework.cloud.stream.binder.rabbit.provisioning.RabbitExchangeQueueProvisioner.java

private Binding partitionedBinding(String destination, Exchange exchange, Queue queue,
        RabbitCommonProperties extendedProperties, int index) {
    String bindingKey = extendedProperties.getBindingRoutingKey();
    if (bindingKey == null) {
        bindingKey = destination;/*from   w ww .  j  a v a  2 s . c o m*/
    }
    bindingKey += "-" + index;
    if (exchange instanceof TopicExchange) {
        Binding binding = BindingBuilder.bind(queue).to((TopicExchange) exchange).with(bindingKey);
        declareBinding(queue.getName(), binding);
        return binding;
    } else if (exchange instanceof DirectExchange) {
        Binding binding = BindingBuilder.bind(queue).to((DirectExchange) exchange).with(bindingKey);
        declareBinding(queue.getName(), binding);
        return binding;
    } else if (exchange instanceof FanoutExchange) {
        throw new ProvisioningException("A fanout exchange is not appropriate for partitioned apps");
    } else {
        throw new ProvisioningException("Cannot bind to a " + exchange.getType() + " exchange");
    }
}

From source file:org.springframework.cloud.stream.binder.rabbit.provisioning.RabbitExchangeQueueProvisioner.java

private Binding notPartitionedBinding(Exchange exchange, Queue queue,
        RabbitCommonProperties extendedProperties) {
    String routingKey = extendedProperties.getBindingRoutingKey();
    if (routingKey == null) {
        routingKey = "#";
    }/*w w w . jav a2s .  c o m*/
    if (exchange instanceof TopicExchange) {
        Binding binding = BindingBuilder.bind(queue).to((TopicExchange) exchange).with(routingKey);
        declareBinding(queue.getName(), binding);
        return binding;
    } else if (exchange instanceof DirectExchange) {
        Binding binding = BindingBuilder.bind(queue).to((DirectExchange) exchange).with(routingKey);
        declareBinding(queue.getName(), binding);
        return binding;
    } else if (exchange instanceof FanoutExchange) {
        Binding binding = BindingBuilder.bind(queue).to((FanoutExchange) exchange);
        declareBinding(queue.getName(), binding);
        return binding;
    } else {
        throw new ProvisioningException("Cannot bind to a " + exchange.getType() + " exchange");
    }
}

From source file:org.springframework.cloud.stream.binder.rabbit.provisioning.RabbitExchangeQueueProvisioner.java

/**
 * If so requested, declare the DLX/DLQ and bind it. The DLQ is bound to the DLX with a routing key of the original
 * queue name because we use default exchange routing by queue name for the original message.
 * @param baseQueueName   The base name for the queue (including the binder prefix, if any).
 * @param routingKey  The routing key for the queue.
 * @param properties the properties./*from www  .jav a2  s . c  o  m*/
 */
private void autoBindDLQ(final String baseQueueName, String routingKey, RabbitCommonProperties properties) {
    boolean autoBindDlq = properties.isAutoBindDlq();
    if (this.logger.isDebugEnabled()) {
        this.logger.debug("autoBindDLQ=" + autoBindDlq + " for: " + baseQueueName);
    }
    if (autoBindDlq) {
        String dlqName;
        if (properties.getDeadLetterQueueName() == null) {
            dlqName = constructDLQName(baseQueueName);
        } else {
            dlqName = properties.getDeadLetterQueueName();
        }
        Queue dlq = new Queue(dlqName, true, false, false, queueArgs(dlqName, properties, true));
        declareQueue(dlqName, dlq);
        String dlxName = deadLetterExchangeName(properties);
        final DirectExchange dlx = new DirectExchange(dlxName);
        declareExchange(dlxName, dlx);
        BindingBuilder.DirectExchangeRoutingKeyConfigurer bindingBuilder = BindingBuilder.bind(dlq).to(dlx);
        Binding dlqBinding;
        if (properties.getDeadLetterRoutingKey() == null) {
            dlqBinding = bindingBuilder.with(routingKey);
        } else {
            dlqBinding = bindingBuilder.with(properties.getDeadLetterRoutingKey());
        }
        declareBinding(dlqName, dlqBinding);
        if (properties instanceof RabbitConsumerProperties
                && ((RabbitConsumerProperties) properties).isRepublishToDlq()) {
            /*
             *  Also bind with the base queue name when republishToDlq is used, which does not know about
             * partitioning
             */
            declareBinding(dlqName, BindingBuilder.bind(dlq).to(dlx).with(baseQueueName));
        }
    }
}

From source file:org.springframework.cloud.stream.binder.rabbit.RabbitBinderTests.java

@Test
public void testConsumerPropertiesWithUserInfrastructureNoBind() throws Exception {
    RabbitAdmin admin = new RabbitAdmin(this.rabbitAvailableRule.getResource());
    Queue queue = new Queue("propsUser1.infra");
    admin.declareQueue(queue);/*from  w w w. j a va2s . c  o m*/
    DirectExchange exchange = new DirectExchange("propsUser1");
    admin.declareExchange(exchange);
    admin.declareBinding(BindingBuilder.bind(queue).to(exchange).with("foo"));

    RabbitTestBinder binder = getBinder();
    ExtendedConsumerProperties<RabbitConsumerProperties> properties = createConsumerProperties();
    properties.getExtension().setDeclareExchange(false);
    properties.getExtension().setBindQueue(false);

    Binding<MessageChannel> consumerBinding = binder.bindConsumer("propsUser1", "infra",
            createBindableChannel("input", new BindingProperties()), properties);
    Lifecycle endpoint = extractEndpoint(consumerBinding);
    SimpleMessageListenerContainer container = TestUtils.getPropertyValue(endpoint, "messageListenerContainer",
            SimpleMessageListenerContainer.class);
    assertThat(container.isRunning()).isTrue();
    consumerBinding.unbind();
    assertThat(container.isRunning()).isFalse();
    RabbitManagementTemplate rmt = new RabbitManagementTemplate();
    List<org.springframework.amqp.core.Binding> bindings = rmt.getBindingsForExchange("/", exchange.getName());
    assertThat(bindings.size()).isEqualTo(1);
}

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

@Override
public void tap(String tapModule, final String name, MessageChannel tapModuleInputChannel) {
    SimpleMessageListenerContainer listenerContainer = new SimpleMessageListenerContainer(
            this.connectionFactory);
    if (this.concurrentConsumers != null) {
        listenerContainer.setConcurrentConsumers(this.concurrentConsumers);
    }/*from   w w  w.  ja  v  a  2s .com*/
    Queue queue = this.rabbitAdmin.declareQueue();
    Binding binding = BindingBuilder.bind(queue).to(new FanoutExchange("tap." + name));
    this.rabbitAdmin.declareBinding(binding);
    listenerContainer.setQueues(queue);
    listenerContainer.afterPropertiesSet();
    AmqpInboundChannelAdapter adapter = new AmqpInboundChannelAdapter(listenerContainer);
    DirectChannel bridgeToTapChannel = new DirectChannel();
    bridgeToTapChannel.setBeanName(tapModule + ".bridge");
    adapter.setOutputChannel(bridgeToTapChannel);
    adapter.setHeaderMapper(this.mapper);
    adapter.setBeanName("tap." + name);
    adapter.setComponentName(tapModule + "." + "tapAdapter");
    adapter.afterPropertiesSet();
    this.lifecycleBeans.add(adapter);
    // TODO: media types need to be passed in by Tap.
    Collection<MediaType> acceptedMediaTypes = Collections.singletonList(MediaType.ALL);
    ReceivingHandler convertingBridge = new ReceivingHandler(acceptedMediaTypes);
    convertingBridge.setOutputChannel(tapModuleInputChannel);
    convertingBridge.setBeanName(name + ".convert.bridge");
    convertingBridge.afterPropertiesSet();
    bridgeToTapChannel.subscribe(convertingBridge);
    adapter.start();
}