Example usage for org.springframework.amqp.core ExchangeTypes FANOUT

List of usage examples for org.springframework.amqp.core ExchangeTypes FANOUT

Introduction

In this page you can find the example usage for org.springframework.amqp.core ExchangeTypes FANOUT.

Prototype

String FANOUT

To view the source code for org.springframework.amqp.core ExchangeTypes FANOUT.

Click Source Link

Document

Fanout exchange.

Usage

From source file:com.github.larsq.spring.embeddedamqp.SimpleAmqpMessageContainer.java

protected Address defineAddress(String exchangeName, String routingKey) {
    if (exchangeName != null && routingKey != null) {
        return new Address(ExchangeTypes.DIRECT, exchangeName, routingKey);
    }/*from  w  ww .j ava2 s.  c  o m*/

    if (exchangeName == null) {
        return new Address(ExchangeTypes.TOPIC, null, routingKey);
    }

    if (routingKey == null) {
        return new Address(ExchangeTypes.FANOUT, exchangeName, null);
    }

    //both are null
    throw new NullPointerException("both exchange and routing key cannot be null");
}

From source file:org.springframework.amqp.rabbit.annotation.RabbitListenerAnnotationBeanPostProcessor.java

private void declareExchangeAndBinding(QueueBinding binding, String queueName) {
    org.springframework.amqp.rabbit.annotation.Exchange bindingExchange = binding.exchange();
    String exchangeName = resolveExpressionAsString(bindingExchange.value(), "@Exchange.exchange");
    Assert.isTrue(StringUtils.hasText(exchangeName), "Exchange name required; binding queue " + queueName);
    String exchangeType = resolveExpressionAsString(bindingExchange.type(), "@Exchange.type");
    String routingKey = resolveExpressionAsString(binding.key(), "@QueueBinding.key");
    Exchange exchange;/* w ww.jav a 2  s . c om*/
    Binding actualBinding;
    if (exchangeType.equals(ExchangeTypes.DIRECT)) {
        exchange = directExchange(bindingExchange, exchangeName);
        actualBinding = new Binding(queueName, DestinationType.QUEUE, exchangeName, routingKey,
                resolveArguments(binding.arguments()));
    } else if (exchangeType.equals(ExchangeTypes.FANOUT)) {
        exchange = fanoutExchange(bindingExchange, exchangeName);
        actualBinding = new Binding(queueName, DestinationType.QUEUE, exchangeName, "",
                resolveArguments(binding.arguments()));
    } else if (exchangeType.equals(ExchangeTypes.TOPIC)) {
        exchange = topicExchange(bindingExchange, exchangeName);
        actualBinding = new Binding(queueName, DestinationType.QUEUE, exchangeName, routingKey,
                resolveArguments(binding.arguments()));
    } else if (exchangeType.equals(ExchangeTypes.HEADERS)) {
        exchange = headersExchange(bindingExchange, exchangeName);
        actualBinding = new Binding(queueName, DestinationType.QUEUE, exchangeName, routingKey,
                resolveArguments(binding.arguments()));
    } else {
        throw new BeanInitializationException("Unexpected exchange type: " + exchangeType);
    }
    AbstractExchange abstractExchange = (AbstractExchange) exchange;
    abstractExchange.setInternal(resolveExpressionAsBoolean(bindingExchange.internal()));
    abstractExchange.setIgnoreDeclarationExceptions(
            resolveExpressionAsBoolean(bindingExchange.ignoreDeclarationExceptions()));
    ((AbstractDeclarable) actualBinding)
            .setIgnoreDeclarationExceptions(resolveExpressionAsBoolean(binding.ignoreDeclarationExceptions()));
    ((ConfigurableBeanFactory) this.beanFactory).registerSingleton(exchangeName + ++this.increment, exchange);
    ((ConfigurableBeanFactory) this.beanFactory)
            .registerSingleton(exchangeName + "." + queueName + ++this.increment, actualBinding);
}

From source file:org.springframework.amqp.samples.log4j2.SpringBootAmqpAppenderApplication.java

@RabbitListener(bindings = @QueueBinding(exchange = @Exchange(value = "log4j2Sample", type = ExchangeTypes.FANOUT), value = @org.springframework.amqp.rabbit.annotation.Queue))
public void echoLogs(String logMessage) {
    System.out.println("Logs over Log4J AmqpAppender: " + logMessage);
}