/** * Sets the name of the exchange to dispatch published messages to. Defaults to the exchange named * "{@code Axon.EventBus}". * * @param exchange the exchange to dispatch messages to */ public void setExchange(Exchange exchange) { this.exchangeName = exchange.getName(); }
@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 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); } } } }
if ((!exchange.isDurable() || exchange.isAutoDelete()) && this.logger.isInfoEnabled()) { this.logger.info("Auto-declaring a non-durable or auto-delete Exchange (" + exchange.getName() + ") durable:" + exchange.isDurable() + ", auto-delete:" + exchange.isAutoDelete() + ". " + "It will be deleted by the broker if it shuts down, and can be redeclared by closing and " + "reopening the connection.");
@Test public void testExchangeBuilder() { Exchange exchange = ExchangeBuilder.directExchange("foo").autoDelete().delayed().internal() .withArgument("foo", "bar").build(); assertThat(exchange, instanceOf(DirectExchange.class)); assertTrue(exchange.isAutoDelete()); assertTrue(exchange.isDurable()); assertTrue(exchange.isInternal()); assertTrue(exchange.isDelayed()); assertThat((String) exchange.getArguments().get("foo"), equalTo("bar")); exchange = ExchangeBuilder.topicExchange("foo").durable(false).build(); assertThat(exchange, instanceOf(TopicExchange.class)); assertFalse(exchange.isAutoDelete()); assertFalse(exchange.isDurable()); assertFalse(exchange.isInternal()); assertFalse(exchange.isDelayed()); exchange = ExchangeBuilder.fanoutExchange("foo").build(); assertThat(exchange, instanceOf(FanoutExchange.class)); assertFalse(exchange.isAutoDelete()); assertTrue(exchange.isDurable()); assertFalse(exchange.isInternal()); assertFalse(exchange.isDelayed()); exchange = ExchangeBuilder.headersExchange("foo").build(); assertThat(exchange, instanceOf(HeadersExchange.class)); assertFalse(exchange.isAutoDelete()); assertTrue(exchange.isDurable()); assertFalse(exchange.isInternal()); assertFalse(exchange.isDelayed()); }
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()); }
@Override public UnaryOperator<Exchange> alternateExchange(final String name) { return (Exchange exchange) -> { exchange.getArguments().put("alternate-exchange", name); return exchange; }; }
if ((!exchange.isDurable() || exchange.isAutoDelete()) && this.logger.isInfoEnabled()) { this.logger.info("Auto-declaring a non-durable or auto-delete Exchange (" + exchange.getName() + ") durable:" + exchange.isDurable() + ", auto-delete:" + exchange.isAutoDelete() + ". " + "It will be deleted by the broker if it shuts down, and can be redeclared by closing and " + "reopening the connection.");
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"); } }
/** * Sets the name of the exchange to dispatch published messages to. Defaults to the exchange named * "{@code Axon.EventBus}". * * @param exchange the exchange to dispatch messages to */ public void setExchange(Exchange exchange) { this.exchangeName = exchange.getName(); }
@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 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 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"); } }
GenericExchangeRoutingKeyConfigurer(DestinationConfigurer destination, Exchange exchange) { super(destination, exchange.getName()); }
@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"); } }
@Override public String getName() { return this.exchange.getName(); }
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"); } }
@Override public String getName() { return this.exchange.getName(); }
@Override public String getNameForPartition(int partition) { return this.exchange.getName(); }