private void declareBindings(final Channel channel, final Binding... bindings) throws IOException { for (Binding binding : bindings) { if (this.logger.isDebugEnabled()) { this.logger.debug("Binding destination [" + binding.getDestination() + " (" + binding.getDestinationType() + ")] to exchange [" + binding.getExchange() + "] with routing key [" + binding.getRoutingKey() + "]"); } try { if (binding.isDestinationQueue()) { if (!isDeclaringImplicitQueueBinding(binding)) { channel.queueBind(binding.getDestination(), binding.getExchange(), binding.getRoutingKey(), binding.getArguments()); } } else { channel.exchangeBind(binding.getDestination(), binding.getExchange(), binding.getRoutingKey(), binding.getArguments()); } } catch (IOException e) { logOrRethrowDeclarationException(binding, "binding", e); } } }
public Binding and(Map<String, Object> map) { return new Binding(this.configurer.destination.name, this.configurer.destination.type, this.configurer.exchange, this.routingKey, map); }
@Override public Binding getObject() { String destination; DestinationType destinationType; if (this.destinationQueue != null) { destination = this.destinationQueue.getName(); destinationType = DestinationType.QUEUE; } else { destination = this.destinationExchange.getName(); destinationType = DestinationType.EXCHANGE; } Binding binding = new Binding(destination, destinationType, this.exchange, this.routingKey, this.arguments); if (this.shouldDeclare != null) { binding.setShouldDeclare(this.shouldDeclare); } if (this.ignoreDeclarationExceptions != null) { binding.setIgnoreDeclarationExceptions(this.ignoreDeclarationExceptions); } if (this.adminsThatShouldDeclare != null) { binding.setAdminsThatShouldDeclare((Object[]) this.adminsThatShouldDeclare); } return binding; }
/** * Add a binding * */ public RabbitContextBuilder add(Binding binding) { bindings.put(Arrays.toString(new String[] {binding.getExchange(), binding.getExchange(), binding.getRoutingKey()}), binding); return this; }
private boolean isImplicitQueueBinding(Binding binding) { return isDefaultExchange(binding.getExchange()) && binding.getDestination().equals(binding.getRoutingKey()); }
@Test public void testBindings() throws Exception { Map<String, Binding> bindings = beanFactory.getBeansOfType(Binding.class); // 4 for each exchange type assertEquals(13, bindings.size()); for (Map.Entry<String, Binding> bindingEntry : bindings.entrySet()) { Binding binding = bindingEntry.getValue(); if ("headers-test".equals(binding.getExchange()) && "bucket".equals(binding.getDestination())) { Map<String, Object> arguments = binding.getArguments(); assertEquals(3, arguments.size()); break; } } }
@Bean public Binding binding() throws IOException { Binding binding = new Binding("foo", DestinationType.QUEUE, exchange().getName(), "foo", null); binding.setAdminsThatShouldDeclare(admin1()); return binding; } }
/** * The message consumer for the service control messages. * * @return The message consumer for the service responses. * * @since 1.0 */ @Bean IAmqpCapabilityRegistryControlConsumer capabilityRegistryControlConsumer() { final String replyTo = this.capabilityRegistryControlQueueBinding.getRoutingKey(); return new AmqpCapabilityRegistryControlConsumer(replyTo, this.capabilityRegistryControlProducer); }
exchange.setShouldDeclare(false); context.getBeanFactory().registerSingleton("bar", exchange); Binding binding = new Binding("foo", DestinationType.QUEUE, "bar", "foo", null); binding.setShouldDeclare(false); context.getBeanFactory().registerSingleton("baz", binding); context.refresh();
@Test public void testDirectExchange() throws Exception { DirectExchange exchange = beanFactory.getBean("direct", DirectExchange.class); assertNotNull(exchange); assertEquals("direct", exchange.getName()); assertTrue(exchange.isDurable()); assertFalse(exchange.isAutoDelete()); assertFalse(exchange.shouldDeclare()); assertEquals(2, exchange.getDeclaringAdmins().size()); Binding binding = beanFactory.getBean("org.springframework.amqp.rabbit.config.BindingFactoryBean#0", Binding.class); assertFalse(binding.shouldDeclare()); assertEquals(2, binding.getDeclaringAdmins().size()); Map<String, Object> arguments = binding.getArguments(); assertNotNull(arguments); assertEquals(1, arguments.size()); assertTrue(arguments.containsKey("x-match")); assertEquals("any", arguments.get("x-match")); }
binding.setAdminsThatShouldDeclare(rabbitAdmin);
private boolean isImplicitQueueBinding(Binding binding) { return isDefaultExchange(binding.getExchange()) && binding.getDestination().equals(binding.getRoutingKey()); }
/** * Add a binding * */ public RabbitContextBuilder add(Binding binding) { bindings.put(Arrays.toString(new String[] {binding.getExchange(), binding.getExchange(), binding.getRoutingKey()}), binding); return this; }
exchange.setAdminsThatShouldDeclare(admin); context.getBeanFactory().registerSingleton("bar", exchange); Binding binding = new Binding("foo", DestinationType.QUEUE, "bar", "foo", null); binding.setAdminsThatShouldDeclare(admin); context.getBeanFactory().registerSingleton("baz", binding); context.refresh();
/** * The message consumer for the service responses. * * @return The message consumer for the service responses. * * @since 1.0 */ @Bean("name=capabilityRegistryServiceConsumer") IAmqpCapabilityRegistryServiceConsumer capabilityRegistryServiceConsumer() { final String replyTo = this.capabilityRegistryResponseQueueBinding.getRoutingKey(); return new AmqpCapabilityRegistryServiceConsumer(replyTo); }
private void declareBindings(final Channel channel, final Binding... bindings) throws IOException { for (Binding binding : bindings) { if (this.logger.isDebugEnabled()) { this.logger.debug("Binding destination [" + binding.getDestination() + " (" + binding.getDestinationType() + ")] to exchange [" + binding.getExchange() + "] with routing key [" + binding.getRoutingKey() + "]"); } try { if (binding.isDestinationQueue()) { if (!isDeclaringImplicitQueueBinding(binding)) { channel.queueBind(binding.getDestination(), binding.getExchange(), binding.getRoutingKey(), binding.getArguments()); } } else { channel.exchangeBind(binding.getDestination(), binding.getExchange(), binding.getRoutingKey(), binding.getArguments()); } } catch (IOException e) { logOrRethrowDeclarationException(binding, "binding", e); } } }
bindings.stream().filter(b -> q.getName().equals(b.getDestination())).forEach(b -> MessageExchangeDto exchange = exchangeMap.get(b.getExchange()); if (exchange == null) exchange = new MessageExchangeDto(b.getExchange(), MessageDirectionType.CONSUME); exchangeMap.put(b.getExchange(), exchange); List<BindingDataDto> exchangeBinding = exchangeToBindingMap.get(b.getExchange()); if (exchangeBinding == null) exchangeToBindingMap.put(b.getExchange(), exchangeBinding); exchangeBinding.add(new BindingDataDto(b.getDestination(), b.getRoutingKey())); }); });
public Binding withQueueName() { return new Binding(destination.name, destination.type, exchange, destination.name, Collections.<String, Object>emptyMap()); } }
@Override public Binding getObject() { String destination; DestinationType destinationType; if (this.destinationQueue != null) { destination = this.destinationQueue.getName(); destinationType = DestinationType.QUEUE; } else { destination = this.destinationExchange.getName(); destinationType = DestinationType.EXCHANGE; } Binding binding = new Binding(destination, destinationType, this.exchange, this.routingKey, this.arguments); if (this.shouldDeclare != null) { binding.setShouldDeclare(this.shouldDeclare); } if (this.ignoreDeclarationExceptions != null) { binding.setIgnoreDeclarationExceptions(this.ignoreDeclarationExceptions); } if (this.adminsThatShouldDeclare != null) { binding.setAdminsThatShouldDeclare((Object[]) this.adminsThatShouldDeclare); } return binding; }
exchange.setAdminsThatShouldDeclare(other); context.getBeanFactory().registerSingleton("bar", exchange); Binding binding = new Binding("foo", DestinationType.QUEUE, "bar", "foo", null); binding.setAdminsThatShouldDeclare(other); context.getBeanFactory().registerSingleton("baz", binding); context.refresh();