LOG.info("Declared queue {} for endpoint {}.", queue.getName(), endpoint);
return queue;
}
protected Binding declareBinding(org.springframework.amqp.core.Exchange exchange, Queue queue) {
Binding binding = null;
//Is this a header exchange? Bind the key/value pair(s)
if(exchange instanceof HeadersExchange) {
if(this.endpoint.routingKey == null)
throw new IllegalStateException("Specified a header exchange without a key/value match");
if(this.endpoint.routingKey.contains("|") && this.endpoint.routingKey.contains("&"))
throw new IllegalArgumentException("You cannot mix AND and OR expressions within a header binding");
Map<String, Object> keyValues = parseKeyValues(this.endpoint.routingKey);
BindingBuilder.HeadersExchangeMapConfigurer mapConfig = BindingBuilder.bind(queue).to((HeadersExchange) exchange);
if(this.endpoint.routingKey.contains("|"))
binding = mapConfig.whereAny(keyValues).match();
else
binding = mapConfig.whereAll(keyValues).match();
//Is this a fanout exchange? Just bind the queue and exchange directly
} else if(exchange instanceof FanoutExchange) {
binding = BindingBuilder.bind(queue).to((FanoutExchange) exchange);
//Perform routing key binding for direct or topic exchanges
} else {
binding = BindingBuilder.bind(queue).to(exchange).with(this.endpoint.routingKey).noargs();
}
if (this.endpoint.isUsingDefaultExchange()) {
LOG.info("Using default exchange for endpoint {}. Default exchange is implicitly bound to every queue, with a routing key equal to the queue name.", endpoint);
} else if (binding != null) {
LOG.info("Declaring binding {} for endpoint {}.", binding.getRoutingKey(), endpoint);
this.endpoint.getAmqpAdministration().declareBinding(binding);
}
return binding;
}