org.springframework.amqp.core.Binding.DestinationType Java Examples

The following examples show how to use org.springframework.amqp.core.Binding.DestinationType. 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: MQClient.java    From zxl with Apache License 2.0 6 votes vote down vote up
@Override
public void afterPropertiesSet() throws Exception {
	List<RabbitAdmin> rabbitAdmins = getMqAdmins();
	for (int i = 0; i < rabbitAdmins.size(); i++) {
		RabbitAdmin rabbitAdmin = rabbitAdmins.get(i);
		while (true) {
			if (!DEFAULT_EXCHANGE.equals(exchange)) {
				break;
			}
			try {
				rabbitAdmin.declareQueue(new Queue(routingKey, queueDurable, queueExclusive, queueAutoDelete, queueArguments));
				rabbitAdmin.declareBinding(new Binding(routingKey, DestinationType.QUEUE, MQClient.DEFAULT_EXCHANGE, routingKey, bindingArguments));
				break;
			} catch (Exception e) {
				LogUtil.warn(logger, "�������У�" + routingKey + "��ʧ��", e);
			}
		}
	}
}
 
Example #2
Source File: MessageListenerAccessor.java    From spring-cloud-contract with Apache License 2.0 5 votes vote down vote up
private Set<String> collectQueuesBoundToDestination(String destination,
		String routingKey) {
	Set<String> queueNames = new HashSet<>();
	for (Binding binding : this.bindings) {
		if (destination.equals(binding.getExchange())
				&& (routingKey == null || routingKey.equals(binding.getRoutingKey()))
				&& DestinationType.QUEUE.equals(binding.getDestinationType())) {
			queueNames.add(binding.getDestination());
		}
	}
	return queueNames;
}
 
Example #3
Source File: MQServer.java    From zxl with Apache License 2.0 5 votes vote down vote up
protected void handleReceiveError(Exception warnException, RabbitAdmin mqAdmin) {
	Throwable throwable = warnException;
	while ((throwable = throwable.getCause()) != null) {
		if (throwable instanceof ShutdownSignalException && throwable.getMessage().contains(NOT_FOUND_MESSAGE)) {
			try {
				mqAdmin.declareQueue(new Queue(queueName, queueDurable, queueExclusive, queueAutoDelete, queueArguments));
				mqAdmin.declareBinding(new Binding(queueName, DestinationType.QUEUE, MQClient.DEFAULT_EXCHANGE, queueName, bindingArguments));
			} catch (Exception e) {
			}
			break;
		}
	}
}
 
Example #4
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));
		}
	}
}