List of usage examples for org.springframework.amqp.core Queue Queue
public Queue(String name, boolean durable, boolean exclusive, boolean autoDelete, Map<String, Object> arguments)
From source file:jp.co.ctc_g.rack.core.config.RackAmqpConfig.java
/** * DI????//from ww w . j a va 2 s. co m * @return */ @Bean public Queue resourceConsumerQueue() { return new Queue("process.control.message.queue", true, false, false, deadLetterArguments()); }
From source file:jp.co.ctc_g.rack.core.config.RackAmqpConfig.java
/** * DI????//from w ww .j a v a 2 s . c o m * @return */ @Bean public Queue keypairConsumerQueue() { return new Queue("keypair.control.message.queue", true, false, false, deadLetterArguments()); }
From source file:jp.co.ctc_g.rack.core.config.RackAmqpConfig.java
/** * DI????/*from w ww . java 2 s . co m*/ * @return */ @Bean public Queue networkConsumerQueue() { return new Queue("network.control.message.queue", true, false, false, deadLetterArguments()); }
From source file:org.springframework.cloud.netflix.turbine.amqp.TurbineAmqpAutoConfiguration.java
@Bean public Queue hystrixStreamQueue() { Map<String, Object> args = new HashMap<>(); args.put("x-message-ttl", 60000); // TODO: configure TTL Queue queue = new Queue(HystrixConstants.HYSTRIX_STREAM_NAME, false, false, false, args); return queue; }
From source file:org.springframework.amqp.rabbit.annotation.RabbitListenerAnnotationBeanPostProcessor.java
private String declareQueue(org.springframework.amqp.rabbit.annotation.Queue bindingQueue) { String queueName = (String) resolveExpression(bindingQueue.value()); boolean exclusive = false; boolean autoDelete = false; if (!StringUtils.hasText(queueName)) { queueName = UUID.randomUUID().toString(); // default exclusive/autodelete to true when anonymous if (!StringUtils.hasText(bindingQueue.exclusive()) || resolveExpressionAsBoolean(bindingQueue.exclusive())) { exclusive = true;//from w w w. ja v a 2 s. c o m } if (!StringUtils.hasText(bindingQueue.autoDelete()) || resolveExpressionAsBoolean(bindingQueue.autoDelete())) { autoDelete = true; } } else { exclusive = resolveExpressionAsBoolean(bindingQueue.exclusive()); autoDelete = resolveExpressionAsBoolean(bindingQueue.autoDelete()); } Queue queue = new Queue(queueName, resolveExpressionAsBoolean(bindingQueue.durable()), exclusive, autoDelete, resolveArguments(bindingQueue.arguments())); queue.setIgnoreDeclarationExceptions( resolveExpressionAsBoolean(bindingQueue.ignoreDeclarationExceptions())); ((ConfigurableBeanFactory) this.beanFactory).registerSingleton(queueName + ++this.increment, queue); return queueName; }
From source file:org.springframework.amqp.rabbit.listener.DirectMessageListenerContainerIntegrationTests.java
@Test public void testErrorHandler() throws Exception { brokerRunning.deleteQueues(Q1);/*from w w w. java2 s. c om*/ Queue q1 = new Queue(Q1, true, false, false, new ArgumentBuilder().put("x-dead-letter-exchange", "") .put("x-dead-letter-routing-key", DLQ1).get()); CachingConnectionFactory cf = new CachingConnectionFactory("localhost"); RabbitAdmin admin = new RabbitAdmin(cf); admin.declareQueue(q1); DirectMessageListenerContainer container = new DirectMessageListenerContainer(cf); container.setQueueNames(Q1); container.setConsumersPerQueue(2); final AtomicReference<Channel> channel = new AtomicReference<>(); container.setMessageListener((ChannelAwareMessageListener) (m, c) -> { channel.set(c); throw new MessageConversionException( "intended - should be wrapped in an AmqpRejectAndDontRequeueException"); }); container.setBeanName("errorHandler"); container.setConsumerTagStrategy(new Tag()); container.afterPropertiesSet(); container.start(); RabbitTemplate template = new RabbitTemplate(cf); template.convertAndSend(Q1, "foo"); assertNotNull(template.receive(DLQ1, 10000)); container.stop(); assertTrue(consumersOnQueue(Q1, 0)); assertTrue(consumersOnQueue(Q2, 0)); assertTrue(activeConsumerCount(container, 0)); assertEquals(0, TestUtils.getPropertyValue(container, "consumersByQueue", MultiValueMap.class).size()); assertFalse(channel.get().isOpen()); cf.destroy(); }
From source file:org.springframework.amqp.rabbit.listener.DirectMessageListenerContainerTests.java
@Test public void testErrorHandler() throws Exception { brokerRunning.getAdmin().deleteQueue(Q1); Queue q1 = new Queue(Q1, true, false, false, new ArgumentBuilder().put("x-dead-letter-exchange", "") .put("x-dead-letter-routing-key", DLQ1).get()); brokerRunning.getAdmin().declareQueue(q1); CachingConnectionFactory cf = new CachingConnectionFactory("localhost"); DirectMessageListenerContainer container = new DirectMessageListenerContainer(cf); container.setQueueNames(Q1);/*from w ww. j av a 2s . c o m*/ container.setConsumersPerQueue(2); final AtomicReference<Channel> channel = new AtomicReference<>(); container.setMessageListener((ChannelAwareMessageListener) (m, c) -> { channel.set(c); throw new MessageConversionException( "intended - should be wrapped in an AmqpRejectAndDontRequeueException"); }); container.setBeanName("errorHandler"); container.setConsumerTagStrategy(new Tag()); container.afterPropertiesSet(); container.start(); RabbitTemplate template = new RabbitTemplate(cf); template.convertAndSend(Q1, "foo"); assertNotNull(template.receive(DLQ1, 10000)); container.stop(); assertTrue(consumersOnQueue(Q1, 0)); assertTrue(consumersOnQueue(Q2, 0)); assertTrue(activeConsumerCount(container, 0)); assertEquals(0, TestUtils.getPropertyValue(container, "consumersByQueue", MultiValueMap.class).size()); assertFalse(channel.get().isOpen()); cf.destroy(); }
From source file:org.springframework.cloud.stream.binder.rabbit.provisioning.RabbitExchangeQueueProvisioner.java
@Override public ProducerDestination provisionProducerDestination(String name, ExtendedProducerProperties<RabbitProducerProperties> producerProperties) { final String exchangeName = applyPrefix(producerProperties.getExtension().getPrefix(), name); Exchange exchange = buildExchange(producerProperties.getExtension(), exchangeName); if (producerProperties.getExtension().isDeclareExchange()) { declareExchange(exchangeName, exchange); }/*w w w . j a va2s. c o m*/ Binding binding = null; for (String requiredGroupName : producerProperties.getRequiredGroups()) { String baseQueueName = exchangeName + "." + requiredGroupName; if (!producerProperties.isPartitioned()) { Queue queue = new Queue(baseQueueName, true, false, false, queueArgs(baseQueueName, producerProperties.getExtension(), false)); declareQueue(baseQueueName, queue); autoBindDLQ(baseQueueName, baseQueueName, producerProperties.getExtension()); if (producerProperties.getExtension().isBindQueue()) { binding = notPartitionedBinding(exchange, queue, producerProperties.getExtension()); } } else { // if the stream is partitioned, create one queue for each target partition for the default group for (int i = 0; i < producerProperties.getPartitionCount(); i++) { String partitionSuffix = "-" + i; String partitionQueueName = baseQueueName + partitionSuffix; Queue queue = new Queue(partitionQueueName, true, false, false, queueArgs(partitionQueueName, producerProperties.getExtension(), false)); declareQueue(queue.getName(), queue); autoBindDLQ(baseQueueName, baseQueueName + partitionSuffix, producerProperties.getExtension()); if (producerProperties.getExtension().isBindQueue()) { String prefix = producerProperties.getExtension().getPrefix(); String destination = StringUtils.isEmpty(prefix) ? exchangeName : exchangeName.substring(prefix.length()); binding = partitionedBinding(destination, exchange, queue, producerProperties.getExtension(), i); } } } } return new RabbitProducerDestination(exchange, binding); }
From source file:org.springframework.cloud.stream.binder.rabbit.provisioning.RabbitExchangeQueueProvisioner.java
@Override public ConsumerDestination provisionConsumerDestination(String name, String group, ExtendedConsumerProperties<RabbitConsumerProperties> properties) { boolean anonymous = !StringUtils.hasText(group); String baseQueueName = anonymous ? groupedName(name, ANONYMOUS_GROUP_NAME_GENERATOR.generateName()) : groupedName(name, group);//from w w w . j a va2 s. c o m if (this.logger.isInfoEnabled()) { this.logger.info("declaring queue for inbound: " + baseQueueName + ", bound to: " + name); } String prefix = properties.getExtension().getPrefix(); final String exchangeName = applyPrefix(prefix, name); Exchange exchange = buildExchange(properties.getExtension(), exchangeName); if (properties.getExtension().isDeclareExchange()) { declareExchange(exchangeName, exchange); } String queueName = applyPrefix(prefix, baseQueueName); boolean partitioned = !anonymous && properties.isPartitioned(); boolean durable = !anonymous && properties.getExtension().isDurableSubscription(); Queue queue; if (anonymous) { queue = new Queue(queueName, false, true, true, queueArgs(queueName, properties.getExtension(), false)); } else { if (partitioned) { String partitionSuffix = "-" + properties.getInstanceIndex(); queueName += partitionSuffix; } if (durable) { queue = new Queue(queueName, true, false, false, queueArgs(queueName, properties.getExtension(), false)); } else { queue = new Queue(queueName, false, false, true, queueArgs(queueName, properties.getExtension(), false)); } } declareQueue(queueName, queue); Binding binding = null; if (properties.getExtension().isBindQueue()) { binding = declareConsumerBindings(name, properties, exchange, partitioned, queue); } if (durable) { autoBindDLQ(applyPrefix(properties.getExtension().getPrefix(), baseQueueName), queueName, properties.getExtension()); } return new RabbitConsumerDestination(queue, binding); }
From source file:org.springframework.cloud.stream.binder.rabbit.provisioning.RabbitExchangeQueueProvisioner.java
/** * If so requested, declare the DLX/DLQ and bind it. The DLQ is bound to the DLX with a routing key of the original * queue name because we use default exchange routing by queue name for the original message. * @param baseQueueName The base name for the queue (including the binder prefix, if any). * @param routingKey The routing key for the queue. * @param properties the properties./*from w w w . jav a2 s . c om*/ */ private void autoBindDLQ(final String baseQueueName, String routingKey, RabbitCommonProperties properties) { boolean autoBindDlq = properties.isAutoBindDlq(); if (this.logger.isDebugEnabled()) { this.logger.debug("autoBindDLQ=" + autoBindDlq + " for: " + baseQueueName); } if (autoBindDlq) { String dlqName; if (properties.getDeadLetterQueueName() == null) { dlqName = constructDLQName(baseQueueName); } else { dlqName = properties.getDeadLetterQueueName(); } Queue dlq = new Queue(dlqName, true, false, false, queueArgs(dlqName, properties, true)); declareQueue(dlqName, dlq); String dlxName = deadLetterExchangeName(properties); final DirectExchange dlx = new DirectExchange(dlxName); declareExchange(dlxName, dlx); BindingBuilder.DirectExchangeRoutingKeyConfigurer bindingBuilder = BindingBuilder.bind(dlq).to(dlx); Binding dlqBinding; if (properties.getDeadLetterRoutingKey() == null) { dlqBinding = bindingBuilder.with(routingKey); } else { dlqBinding = bindingBuilder.with(properties.getDeadLetterRoutingKey()); } declareBinding(dlqName, dlqBinding); if (properties instanceof RabbitConsumerProperties && ((RabbitConsumerProperties) properties).isRepublishToDlq()) { /* * Also bind with the base queue name when republishToDlq is used, which does not know about * partitioning */ declareBinding(dlqName, BindingBuilder.bind(dlq).to(dlx).with(baseQueueName)); } } }