Example usage for org.springframework.amqp.core Address Address

List of usage examples for org.springframework.amqp.core Address Address

Introduction

In this page you can find the example usage for org.springframework.amqp.core Address Address.

Prototype

public Address(String address) 

Source Link

Document

Create an Address instance from a structured String with the form
 (exchange)/(routingKey) 
.

Usage

From source file:org.springframework.amqp.rabbit.listener.adapter.AbstractAdaptableMessageListener.java

/**
 * Set the default replyTo address to use when sending response messages.
 * This is only used if the replyTo from the received message is null.
 * <p>//  w w  w.j a  va 2  s  .c o  m
 * Response destinations are only relevant for listener methods
 * that return result objects, which will be wrapped in
 * a response message and sent to a response destination.
 * <p>
 * Can be a string starting with "SpEL:" in which case the expression is
 * evaluated at runtime; see the reference manual for more information.
 * @param defaultReplyTo The exchange.
 * @since 1.6
 */
public void setResponseAddress(String defaultReplyTo) {
    if (defaultReplyTo.startsWith(PARSER_CONTEXT.getExpressionPrefix())) {
        this.responseExpression = PARSER.parseExpression(defaultReplyTo, PARSER_CONTEXT);
    } else {
        this.responseAddress = new Address(defaultReplyTo);
    }
}

From source file:org.springframework.amqp.rabbit.listener.adapter.AbstractAdaptableMessageListener.java

private Address evaluateReplyTo(Message request, Object source, Object result, Expression expression) {
    Address replyTo = null;//from www .  ja v  a 2s. co  m
    Object value = expression.getValue(this.evalContext, new ReplyExpressionRoot(request, source, result));
    Assert.state(value instanceof String || value instanceof Address,
            "response expression must evaluate to a String or Address");
    if (value instanceof String) {
        replyTo = new Address((String) value);
    } else {
        replyTo = (Address) value;
    }
    return replyTo;
}

From source file:org.springframework.amqp.rabbit.support.RabbitUtils.java

public static MessageProperties createMessageProperties(final BasicProperties source, final Envelope envelope,
        final String charset) {
    MessageProperties target = new MessageProperties();
    Map<String, Object> headers = source.getHeaders();
    if (!CollectionUtils.isEmpty(headers)) {
        for (Map.Entry<String, Object> entry : headers.entrySet()) {
            target.setHeader(entry.getKey(), entry.getValue());
        }/*  w  ww  . j  a  v  a2 s  .  c o  m*/
    }
    target.setTimestamp(source.getTimestamp());
    target.setMessageId(source.getMessageId());
    target.setUserId(source.getUserId());
    target.setAppId(source.getAppId());
    target.setClusterId(source.getClusterId());
    target.setType(source.getType());
    Integer deliverMode = source.getDeliveryMode();
    if (deliverMode != null) {
        target.setDeliveryMode(MessageDeliveryMode.fromInt(deliverMode));
    }
    target.setExpiration(source.getExpiration());
    target.setPriority(source.getPriority());
    target.setContentType(source.getContentType());
    target.setContentEncoding(source.getContentEncoding());
    String correlationId = source.getCorrelationId();
    if (correlationId != null) {
        try {
            target.setCorrelationId(source.getCorrelationId().getBytes(charset));
        } catch (UnsupportedEncodingException ex) {
            throw new AmqpUnsupportedEncodingException(ex);
        }
    }
    String replyTo = source.getReplyTo();
    if (replyTo != null) {
        target.setReplyTo(new Address(replyTo));
    }
    if (envelope != null) {
        target.setReceivedExchange(envelope.getExchange());
        target.setReceivedRoutingKey(envelope.getRoutingKey());
        target.setRedelivered(envelope.isRedeliver());
        target.setDeliveryTag(envelope.getDeliveryTag());
    }
    // TODO: what about messageCount?
    return target;
}