Example usage for org.springframework.integration.amqp.outbound AmqpOutboundEndpoint setRoutingKeyExpression

List of usage examples for org.springframework.integration.amqp.outbound AmqpOutboundEndpoint setRoutingKeyExpression

Introduction

In this page you can find the example usage for org.springframework.integration.amqp.outbound AmqpOutboundEndpoint setRoutingKeyExpression.

Prototype

public void setRoutingKeyExpression(Expression routingKeyExpression) 

Source Link

Usage

From source file:org.springframework.integration.x.rabbit.RabbitMessageBus.java

@Override
public void bindReplier(String name, MessageChannel requests, MessageChannel replies) {
    if (logger.isInfoEnabled()) {
        logger.info("binding replier: " + name);
    }//from   www. ja  v a2s .c  om
    Queue requestQueue = new Queue(name + ".requests");
    this.rabbitAdmin.declareQueue(requestQueue);
    this.doRegisterConsumer(name, requests, requestQueue);

    AmqpOutboundEndpoint replyQueue = new AmqpOutboundEndpoint(rabbitTemplate);
    replyQueue.setBeanFactory(new DefaultListableBeanFactory());
    replyQueue.setRoutingKeyExpression("headers['" + AmqpHeaders.REPLY_TO + "']");
    replyQueue.setHeaderMapper(mapper);
    replyQueue.afterPropertiesSet();
    doRegisterProducer(name, replies, replyQueue);
}

From source file:org.springframework.xd.dirt.integration.rabbit.RabbitMessageBus.java

private AmqpOutboundEndpoint buildOutboundEndpoint(final String name, RabbitPropertiesAccessor properties,
        RabbitTemplate rabbitTemplate) {
    String queueName = 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 {//from ww w. j  ava  2 s  .  c om
        queue.setRoutingKeyExpression(buildPartitionRoutingExpression(queueName));
        for (int i = 0; i < properties.getPartitionCount(); i++) {
            this.rabbitAdmin.declareQueue(new Queue(queueName + "-" + i));
        }
    }
    configureOutboundHandler(queue, properties);
    return queue;
}

From source file:org.springframework.xd.dirt.integration.rabbit.RabbitMessageBus.java

@Override
public void bindReplier(String name, MessageChannel requests, MessageChannel replies, Properties properties) {
    if (logger.isInfoEnabled()) {
        logger.info("binding replier: " + name);
    }//from  w ww. j a v a2  s .co m
    validateConsumerProperties(name, properties, SUPPORTED_REPLYING_CONSUMER_PROPERTIES);
    RabbitPropertiesAccessor accessor = new RabbitPropertiesAccessor(properties);
    Queue requestQueue = new Queue(accessor.getPrefix(this.defaultPrefix) + name + ".requests");
    declareQueueIfNotPresent(requestQueue);
    this.doRegisterConsumer(name, requests, requestQueue, accessor, false);

    AmqpOutboundEndpoint replyQueue = new AmqpOutboundEndpoint(rabbitTemplate);
    replyQueue.setRoutingKeyExpression("headers['" + AmqpHeaders.REPLY_TO + "']");
    configureOutboundHandler(replyQueue, accessor);
    doRegisterProducer(name, replies, replyQueue, accessor);
}