List of usage examples for org.springframework.amqp.core Binding Binding
public Binding(String destination, DestinationType destinationType, String exchange, String routingKey,
Map<String, Object> arguments)
From source file:org.carewebframework.amqp.rabbitmq.Broker.java
/** * Creates an event queue (thread safe) with the correct binding. * // ww w .j av a2s. c o m * @param eventName Name of event handled by queue. */ private synchronized void createEventQueue(String eventName) { if (!queueExists(eventName)) { Queue queue = new Queue(eventName, true, false, true); declareQueue(queue); Binding binding = new Binding(eventName, DestinationType.QUEUE, exchange.getName(), eventName + ".#", null); declareBinding(binding); } }
From source file:org.openbaton.common.vnfm_sdk.amqp.VnfmSpringHelperRabbit.java
@PostConstruct private void init() throws IOException { log.info("Initialization of VnfmSpringHelperRabbit"); rabbitAdmin = new RabbitAdmin(connectionFactory); rabbitAdmin.declareExchange(new TopicExchange("openbaton-exchange")); rabbitAdmin// w w w .j av a 2s . c o m .declareQueue(new Queue(RabbitConfiguration.queueName_vnfmRegister, true, exclusive, autodelete)); rabbitAdmin.declareBinding( new Binding(RabbitConfiguration.queueName_vnfmRegister, Binding.DestinationType.QUEUE, "openbaton-exchange", RabbitConfiguration.queueName_vnfmRegister, null)); }
From source file:crawler.configuration.rabbitmq.RabbitMQConfiguration.java
@Bean Binding binding() {/*from w w w .j a v a 2s . c om*/ Binding binding = new Binding(htmlQueue().getName(), Binding.DestinationType.QUEUE, urlExchange().getName(), "*", new HashMap<>()); amqpAdmin.declareBinding(binding); return binding; }
From source file:org.springframework.amqp.rabbit.annotation.RabbitListenerAnnotationBeanPostProcessor.java
private void declareExchangeAndBinding(QueueBinding binding, String queueName) { org.springframework.amqp.rabbit.annotation.Exchange bindingExchange = binding.exchange(); String exchangeName = resolveExpressionAsString(bindingExchange.value(), "@Exchange.exchange"); Assert.isTrue(StringUtils.hasText(exchangeName), "Exchange name required; binding queue " + queueName); String exchangeType = resolveExpressionAsString(bindingExchange.type(), "@Exchange.type"); String routingKey = resolveExpressionAsString(binding.key(), "@QueueBinding.key"); Exchange exchange;//from w w w. j a va 2s . c o m Binding actualBinding; if (exchangeType.equals(ExchangeTypes.DIRECT)) { exchange = directExchange(bindingExchange, exchangeName); actualBinding = new Binding(queueName, DestinationType.QUEUE, exchangeName, routingKey, resolveArguments(binding.arguments())); } else if (exchangeType.equals(ExchangeTypes.FANOUT)) { exchange = fanoutExchange(bindingExchange, exchangeName); actualBinding = new Binding(queueName, DestinationType.QUEUE, exchangeName, "", resolveArguments(binding.arguments())); } else if (exchangeType.equals(ExchangeTypes.TOPIC)) { exchange = topicExchange(bindingExchange, exchangeName); actualBinding = new Binding(queueName, DestinationType.QUEUE, exchangeName, routingKey, resolveArguments(binding.arguments())); } else if (exchangeType.equals(ExchangeTypes.HEADERS)) { exchange = headersExchange(bindingExchange, exchangeName); actualBinding = new Binding(queueName, DestinationType.QUEUE, exchangeName, routingKey, resolveArguments(binding.arguments())); } else { throw new BeanInitializationException("Unexpected exchange type: " + exchangeType); } AbstractExchange abstractExchange = (AbstractExchange) exchange; abstractExchange.setInternal(resolveExpressionAsBoolean(bindingExchange.internal())); abstractExchange.setIgnoreDeclarationExceptions( resolveExpressionAsBoolean(bindingExchange.ignoreDeclarationExceptions())); ((AbstractDeclarable) actualBinding) .setIgnoreDeclarationExceptions(resolveExpressionAsBoolean(binding.ignoreDeclarationExceptions())); ((ConfigurableBeanFactory) this.beanFactory).registerSingleton(exchangeName + ++this.increment, exchange); ((ConfigurableBeanFactory) this.beanFactory) .registerSingleton(exchangeName + "." + queueName + ++this.increment, actualBinding); }
From source file:org.springframework.amqp.rabbit.core.RabbitAdminTests.java
@Test public void testIgnoreDeclarationExeptionsTimeout() throws Exception { com.rabbitmq.client.ConnectionFactory rabbitConnectionFactory = mock( com.rabbitmq.client.ConnectionFactory.class); TimeoutException toBeThrown = new TimeoutException("test"); doThrow(toBeThrown).when(rabbitConnectionFactory).newConnection(any(ExecutorService.class), anyString()); CachingConnectionFactory ccf = new CachingConnectionFactory(rabbitConnectionFactory); RabbitAdmin admin = new RabbitAdmin(ccf); List<DeclarationExceptionEvent> events = new ArrayList<DeclarationExceptionEvent>(); admin.setApplicationEventPublisher(new EventPublisher(events)); admin.setIgnoreDeclarationExceptions(true); admin.declareQueue(new AnonymousQueue()); admin.declareQueue();/* w w w . j a v a 2 s. c o m*/ admin.declareExchange(new DirectExchange("foo")); admin.declareBinding(new Binding("foo", DestinationType.QUEUE, "bar", "baz", null)); assertThat(events.size(), equalTo(4)); assertThat(events.get(0).getSource(), sameInstance(admin)); assertThat(events.get(0).getDeclarable(), instanceOf(AnonymousQueue.class)); assertSame(toBeThrown, events.get(0).getThrowable().getCause()); assertNull(events.get(1).getDeclarable()); assertSame(toBeThrown, events.get(1).getThrowable().getCause()); assertThat(events.get(2).getDeclarable(), instanceOf(DirectExchange.class)); assertSame(toBeThrown, events.get(2).getThrowable().getCause()); assertThat(events.get(3).getDeclarable(), instanceOf(Binding.class)); assertSame(toBeThrown, events.get(3).getThrowable().getCause()); assertSame(events.get(3), admin.getLastDeclarationExceptionEvent()); }