List of usage examples for org.springframework.amqp.core ExchangeTypes TOPIC
String TOPIC
To view the source code for org.springframework.amqp.core ExchangeTypes TOPIC.
Click Source Link
From source file:com.github.larsq.spring.embeddedamqp.SimpleAmqpMessageContainer.java
void route(Address address, Message message) throws IOException { Preconditions.checkNotNull(address, "Address is not specified"); LOG.debug("route message {} to address {}", message.getEnvelope(), address); /**/*from www . j a v a 2 s . c o m*/ * When address type is TOPIC, these */ if (Objects.equals(address.getExchangeType(), ExchangeTypes.TOPIC)) { topicExchangeRouter.route(null, address.getRoutingKey(), message); return; } ExchangeWrapper exchangeWrapper = exchange(address.getExchangeName()) .orElseThrow(Exception.exchangeNotFound(address.getExchangeName())); exchangeWrapper.counter.incrementAndGet(); exchangeWrapper.router.route(exchangeWrapper, address.getRoutingKey(), message); }
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); }// w w w. ja va 2 s . c om 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;/*from ww w. j a v a 2 s .c o m*/ 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); }