@Override public void bindReplier( String name, MessageChannel requests, MessageChannel replies, Properties properties) { if (logger.isInfoEnabled()) { logger.info("binding replier: " + name); } validateConsumerProperties(name, properties, SUPPORTED_REPLYING_CONSUMER_PROPERTIES); RabbitPropertiesAccessor accessor = new RabbitPropertiesAccessor(properties); Queue requestQueue = new Queue(applyPrefix(accessor.getPrefix(this.defaultPrefix), applyRequests(name))); declareQueueIfNotPresent(requestQueue); this.doRegisterConsumer(name, requests, requestQueue, accessor, false); AmqpOutboundEndpoint replyQueue = new AmqpOutboundEndpoint(rabbitTemplate); replyQueue.setExpressionRoutingKey( EXPRESSION_PARSER.parseExpression("headers['" + AmqpHeaders.REPLY_TO + "']")); configureOutboundHandler(replyQueue, accessor); doRegisterProducer(name, replies, replyQueue, accessor); }
private AmqpOutboundEndpoint buildOutboundEndpoint( final String name, RabbitPropertiesAccessor properties, RabbitTemplate rabbitTemplate) { String queueName = applyPrefix(properties.getPrefix(this.defaultPrefix), name); String partitionKeyExtractorClass = properties.getPartitionKeyExtractorClass(); Expression partitionKeyExpression = properties.getPartitionKeyExpression(); AmqpOutboundEndpoint queue = new AmqpOutboundEndpoint(rabbitTemplate); if (partitionKeyExpression == null && !StringUtils.hasText(partitionKeyExtractorClass)) { declareQueueIfNotPresent(new Queue(queueName)); queue.setRoutingKey(queueName); // uses default exchange } else { queue.setExpressionRoutingKey( EXPRESSION_PARSER.parseExpression(buildPartitionRoutingExpression(queueName))); // if the stream is partitioned, create one queue for each target partition for (int i = 0; i < properties.getNextModuleCount(); i++) { this.rabbitAdmin.declareQueue(new Queue(queueName + "-" + i)); } } configureOutboundHandler(queue, properties); return queue; }
/** * @deprecated in favor of {@link #setExpressionRoutingKey}. Will be changed in a future release * to use an {@link Expression} parameter. * @param routingKeyExpression the expression to set. */ @Deprecated public void setRoutingKeyExpression(String routingKeyExpression) { Assert.hasText(routingKeyExpression); setExpressionRoutingKey(expressionParser.parseExpression(routingKeyExpression)); }