Java Code Examples for org.springframework.amqp.core.Queue#getName()

The following examples show how to use org.springframework.amqp.core.Queue#getName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RabbitExchangeQueueProvisioner.java    From spring-cloud-stream-binder-rabbit with Apache License 2.0 4 votes vote down vote up
/**
 * 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.
 */
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);
		if (properties.isDeclareDlx()) {
			declareExchange(dlxName,
					new ExchangeBuilder(dlxName,
							properties.getDeadLetterExchangeType()).durable(true)
									.build());
		}
		Map<String, Object> arguments = new HashMap<>(properties.getDlqBindingArguments());
		Binding dlqBinding = new Binding(dlq.getName(), DestinationType.QUEUE,
				dlxName, properties.getDeadLetterRoutingKey() == null ? routingKey
						: properties.getDeadLetterRoutingKey(),
				arguments);
		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, new Binding(dlq.getName(), DestinationType.QUEUE,
					dlxName, baseQueueName, arguments));
		}
	}
}
 
Example 2
Source File: AmqpReactiveController.java    From tutorials with MIT License 4 votes vote down vote up
@GetMapping(value = "/topic/{name}", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
public Flux<?> receiveMessagesFromTopic(@PathVariable String name) {

    DestinationsConfig.DestinationInfo d = destinationsConfig.getTopics()
        .get(name);

    if (d == null) {
        return Flux.just(ResponseEntity.notFound()
            .build());
    }

    Queue topicQueue = createTopicQueue(d);
    String qname = topicQueue.getName();

    MessageListenerContainer mlc = messageListenerContainerFactory.createMessageListenerContainer(qname);

    Flux<String> f = Flux.<String> create(emitter -> {

        log.info("[I168] Adding listener, queue={}", qname);

        mlc.setupMessageListener((MessageListener) m -> {

            log.info("[I137] Message received, queue={}", qname);

            if (emitter.isCancelled()) {
                log.info("[I166] cancelled, queue={}", qname);
                mlc.stop();
                return;
            }

            String payload = new String(m.getBody());
            emitter.next(payload);

            log.info("[I176] Message sent to client, queue={}", qname);

        });

        emitter.onRequest(v -> {
            log.info("[I171] Starting container, queue={}", qname);
            mlc.start();
        });

        emitter.onDispose(() -> {
            log.info("[I176] onDispose: queue={}", qname);
            amqpAdmin.deleteQueue(qname);
            mlc.stop();
        });            

        log.info("[I171] Container started, queue={}", qname);

      });
    
    return Flux.interval(Duration.ofSeconds(5))
      .map(v -> {
            log.info("[I209] sending keepalive message...");
            return "No news is good news";
      })
      .mergeWith(f);

}