public Binding bind(Exchange exchange, Queue queue) { if (ExchangeTypes.HEADERS.getValue().equals(exchange.getType()) && CollectionUtils.isEmpty(getArguments())) { throw new RabbitmqConfigurationException(String .format("Invalid Arguments : Arguments must be provided for a header exchange for binding {%s}", this)); } else if (StringUtils.isEmpty(getRoutingKey())) { throw new RabbitmqConfigurationException(String .format("Invalid RoutingKey : RoutingKey must be provided for a non header exchange for binding {%s}", this)); } return BindingBuilder.bind(queue).to(exchange).with(getRoutingKey()).and(getArguments()); }
private void declareExchanges(final Channel channel, final Exchange... exchanges) throws IOException { for (final Exchange exchange : exchanges) { if (this.logger.isDebugEnabled()) { this.logger.debug("declaring Exchange '" + exchange.getName() + "'"); } if (!isDeclaringDefaultExchange(exchange)) { try { if (exchange.isDelayed()) { Map<String, Object> arguments = exchange.getArguments(); if (arguments == null) { arguments = new HashMap<String, Object>(); } else { arguments = new HashMap<String, Object>(arguments); } arguments.put("x-delayed-type", exchange.getType()); channel.exchangeDeclare(exchange.getName(), DELAYED_MESSAGE_EXCHANGE, exchange.isDurable(), exchange.isAutoDelete(), exchange.isInternal(), arguments); } else { channel.exchangeDeclare(exchange.getName(), exchange.getType(), exchange.isDurable(), exchange.isAutoDelete(), exchange.isInternal(), exchange.getArguments()); } } catch (IOException e) { logOrRethrowDeclarationException(exchange, "exchange", e); } } } }
private void declareExchanges(final Channel channel, final Exchange... exchanges) throws IOException { for (final Exchange exchange : exchanges) { if (this.logger.isDebugEnabled()) { this.logger.debug("declaring Exchange '" + exchange.getName() + "'"); } if (!isDeclaringDefaultExchange(exchange)) { try { if (exchange.isDelayed()) { Map<String, Object> arguments = exchange.getArguments(); if (arguments == null) { arguments = new HashMap<String, Object>(); } else { arguments = new HashMap<String, Object>(arguments); } arguments.put("x-delayed-type", exchange.getType()); channel.exchangeDeclare(exchange.getName(), DELAYED_MESSAGE_EXCHANGE, exchange.isDurable(), exchange.isAutoDelete(), exchange.isInternal(), arguments); } else { channel.exchangeDeclare(exchange.getName(), exchange.getType(), exchange.isDurable(), exchange.isAutoDelete(), exchange.isInternal(), exchange.getArguments()); } } catch (IOException e) { logOrRethrowDeclarationException(exchange, "exchange", e); } } } }
@Override public void addExchange(String vhost, Exchange exchange) { ExchangeInfo info = new ExchangeInfo(); info.setArguments(exchange.getArguments()); info.setAutoDelete(exchange.isAutoDelete()); info.setDurable(exchange.isDurable()); info.setType(exchange.getType()); this.rabbitClient.declareExchange(vhost, exchange.getName(), info); }
@Override public void addExchange(String vhost, Exchange exchange) { ExchangeInfo info = new ExchangeInfo(); info.setArguments(exchange.getArguments()); info.setAutoDelete(exchange.isAutoDelete()); info.setDurable(exchange.isDurable()); info.setType(exchange.getType()); this.rabbitClient.declareExchange(vhost, exchange.getName(), info); }
private Binding partitionedBinding(String destination, Exchange exchange, Queue queue, RabbitCommonProperties extendedProperties, int index) { String bindingKey = extendedProperties.getBindingRoutingKey(); if (bindingKey == null) { bindingKey = destination; } 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"); } }
private Binding partitionedBinding(String destination, Exchange exchange, Queue queue, RabbitCommonProperties extendedProperties, int index) { String bindingKey = extendedProperties.getBindingRoutingKey(); if (bindingKey == null) { bindingKey = destination; } 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"); } }
private Binding notPartitionedBinding(Exchange exchange, Queue queue, RabbitCommonProperties extendedProperties) { String routingKey = extendedProperties.getBindingRoutingKey(); if (routingKey == null) { routingKey = "#"; } 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"); } }
@Test public void testDeleteExchange() { String exchangeName = "testExchange"; Exchange testExchange = new DirectExchange(exchangeName); ExchangeInfo info = new ExchangeInfo(); info.setArguments(testExchange.getArguments()); info.setAutoDelete(testExchange.isAutoDelete()); info.setDurable(testExchange.isDurable()); info.setType(testExchange.getType()); this.rabbitRestClient.declareExchange("/", testExchange.getName(), info); ExchangeInfo exchangeToAssert = this.rabbitRestClient.getExchange("/", exchangeName); assertEquals(testExchange.getName(), exchangeToAssert.getName()); assertEquals(testExchange.getType(), exchangeToAssert.getType()); this.rabbitRestClient.deleteExchange("/", testExchange.getName()); assertNull(this.rabbitRestClient.getExchange("/", exchangeName)); }
private Binding notPartitionedBinding(Exchange exchange, Queue queue, RabbitCommonProperties extendedProperties) { String routingKey = extendedProperties.getBindingRoutingKey(); if (routingKey == null) { routingKey = "#"; } 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"); } }