@Bean Binding binding(Queue queue, TopicExchange exchange) { return BindingBuilder.bind(queue).to(exchange).with(queueName); }
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"); } }
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"); } }
template.setExchange(exchange.getName()); admin.declareBinding(BindingBuilder.bind(queue).to(exchange).with("*.end"));
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"); } }
return BindingBuilder.bind(targetEventQueue).to(eventExchange).with(eventRoutingKey);
/** * {@inheritDoc} */ @Override protected Binding createBinding(ProviderEndpoint providerEndpoint) throws CapabilityRegistryException { AmqpProviderEndpointHelper endpointHelper = new AmqpProviderEndpointHelper(providerEndpoint); final String responseExchangeName = endpointHelper.getResponseExchange(); final String responseExchangeType = endpointHelper.getResponseExchangeType(); String responseRoutingKey = routingKeyWithReplyTo(endpointHelper.getResponseRoutingKey()); if ((StringUtils.isBlank(responseExchangeType) && !StringUtils.isBlank(responseRoutingKey)) || ExchangeTypes.TOPIC.equalsIgnoreCase(responseExchangeType)) { TopicExchange responseExchange = new TopicExchange(responseExchangeName); return BindingBuilder.bind(targetResponseQueue).to(responseExchange).with(responseRoutingKey); } else if ((StringUtils.isBlank(responseExchangeType) && StringUtils.isBlank(responseRoutingKey)) || ExchangeTypes.FANOUT.equalsIgnoreCase(responseExchangeType)) { FanoutExchange responseExchange = new FanoutExchange(responseExchangeName); return BindingBuilder.bind(targetResponseQueue).to(responseExchange); } else { throw new CapabilityRegistryException("Unsupported event exchange type: " + responseExchangeType); } }
@Test // @Ignore("Not sure yet if we need to support a use case like this") public void testSendAndReceiveWithTopicConsumeInBackground() throws Exception { RabbitAdmin admin = new RabbitAdmin(connectionFactory); TopicExchange exchange = new TopicExchange("topic"); admin.declareExchange(exchange); template.setExchange(exchange.getName()); admin.declareBinding(BindingBuilder.bind(queue).to(exchange).with("*.end")); final CachingConnectionFactory cachingConnectionFactory = new CachingConnectionFactory(); cachingConnectionFactory.setHost("localhost"); final RabbitTemplate template = new RabbitTemplate(cachingConnectionFactory); template.setExchange(exchange.getName()); BlockingQueueConsumer consumer = template.execute(channel -> { BlockingQueueConsumer consumer1 = createConsumer(template); String tag = consumer1.getConsumerTags().iterator().next(); assertNotNull(tag); return consumer1; }); template.convertAndSend("foo", "message"); String result = getResult(consumer); assertEquals(null, result); template.convertAndSend("foo.end", "message"); result = getResult(consumer); assertEquals("message", result); consumer.stop(); admin.deleteExchange("topic"); cachingConnectionFactory.destroy(); }
@Test public void testSendAndReceiveWithTopicSingleCallback() throws Exception { final RabbitAdmin admin = new RabbitAdmin(connectionFactory); final TopicExchange exchange = new TopicExchange("topic"); admin.declareExchange(exchange); template.setExchange(exchange.getName()); admin.declareBinding(BindingBuilder.bind(queue).to(exchange).with("*.end")); template.execute(channel -> { BlockingQueueConsumer consumer = createConsumer(template); String tag = consumer.getConsumerTags().iterator().next(); assertNotNull(tag); template.convertAndSend("foo", "message"); try { String result = getResult(consumer); assertEquals(null, result); template.convertAndSend("foo.end", "message"); result = getResult(consumer); assertEquals("message", result); } finally { consumer.getChannel().basicCancel(tag); } return null; }); admin.deleteExchange("topic"); }
@Test public void testSendAndReceiveWithNonDefaultExchange() throws Exception { final RabbitAdmin admin = new RabbitAdmin(connectionFactory); final TopicExchange exchange = new TopicExchange("topic"); admin.declareExchange(exchange); admin.declareBinding(BindingBuilder.bind(queue).to(exchange).with("*.end")); template.execute(channel -> { BlockingQueueConsumer consumer = createConsumer(template); String tag = consumer.getConsumerTags().iterator().next(); assertNotNull(tag); template.convertAndSend("topic", "foo", "message"); try { String result = getResult(consumer); assertEquals(null, result); template.convertAndSend("topic", "foo.end", "message"); result = getResult(consumer); assertEquals("message", result); } finally { consumer.getChannel().basicCancel(tag); } return null; }); admin.deleteExchange("topic"); }
/** * This returns the <code>Binding</code> for the service response message queue and exchange. * * @return The <code>Binding</code> for the service response message queue. * * @since 1.0 */ @Bean public Binding capabilityRegistryResponseQueueBinding() { final String bindingPostFix = this.getResponseQueuePostfix(); final StringBuilder builder = new StringBuilder(); builder.append(BINDING_HDP_CAPABILITY_REGISTRY_RESPONSE); builder.append("."); builder.append(bindingPostFix); final String binding = builder.toString(); Object[] lparams = {binding}; LOGGER.info(HDCRMessageCode.SERVICE_RESPONSE_BINDING_I.getMessageCode(), lparams); return BindingBuilder.bind(capabilityRegistryResponseQueue()).to(capabilityRegistryResponseExchange()).with(binding); }
@Override public void onCreate(@Nullable Connection connection) { this.bindingsFailedException = null; TopicExchange exchange = new TopicExchange("amq.rabbitmq.event"); try { this.admin.declareQueue(this.eventQueue); Arrays.stream(this.eventKeys).forEach(k -> { Binding binding = BindingBuilder.bind(this.eventQueue).to(exchange).with(k); this.admin.declareBinding(binding); }); } catch (Exception e) { logger.error("failed to declare event queue/bindings - is the plugin enabled?", e); this.bindingsFailedException = e; } }
@Bean Binding bindingtopicExchangeQueue2(Queue queuetopic2, TopicExchange topicExchange) { return BindingBuilder.bind(queuetopic2).to(topicExchange).with("log.*"); }
@Bean Binding binding(Queue queue, TopicExchange exchange) { return BindingBuilder.bind(queue).to(exchange).with(routingKeyName); }
@Bean Binding binding(Queue queue, TopicExchange exchange) { return BindingBuilder.bind(queue).to(exchange).with(routingKeyName); }
@Override public void onCreate(@Nullable Connection connection) { this.bindingsFailedException = null; TopicExchange exchange = new TopicExchange("amq.rabbitmq.event"); try { this.admin.declareQueue(this.eventQueue); Arrays.stream(this.eventKeys).forEach(k -> { Binding binding = BindingBuilder.bind(this.eventQueue).to(exchange).with(k); this.admin.declareBinding(binding); }); } catch (Exception e) { logger.error("failed to declare event queue/bindings - is the plugin enabled?", e); this.bindingsFailedException = e; } }
@Bean Binding bindingExchangeMessage(Queue quequeMessage,TopicExchange exchange){ return BindingBuilder.bind(quequeMessage).to(exchange).with("topic.message"); }
@Bean Binding binding(Queue queue, TopicExchange exchange) { return BindingBuilder.bind(queue).to(exchange).with(queueName); }
@Bean public Binding topicBinding2() { return BindingBuilder.bind(topicQueue2()).to(topicExchange()).with("topic.#"); }