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 exchangeName, String routingKey) 

Source Link

Document

Create an Address given the exchange name and routing key.

Usage

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

/**
 * Determine a reply-to Address for the given message.
 * <p>/*from  w  ww.  jav  a  2  s . c  o m*/
 * The default implementation first checks the Rabbit Reply-To Address of the supplied request; if that is not
 * <code>null</code> it is returned; if it is <code>null</code>, then the configured default response Exchange and
 * routing key are used to construct a reply-to Address. If the responseExchange property is also <code>null</code>,
 * then an {@link org.springframework.amqp.AmqpException} is thrown.
 * @param request the original incoming Rabbit message.
 * @param source the source data (e.g. {@code o.s.messaging.Message<?>}).
 * @param result the result.
 * @return the reply-to Address (never <code>null</code>)
 * @throws Exception if thrown by Rabbit API methods
 * @throws org.springframework.amqp.AmqpException if no {@link Address} can be determined
 * @see #setResponseAddress(String)
 * @see #setResponseRoutingKey(String)
 * @see org.springframework.amqp.core.Message#getMessageProperties()
 * @see org.springframework.amqp.core.MessageProperties#getReplyTo()
 */
protected Address getReplyToAddress(Message request, Object source, Object result) throws Exception {
    Address replyTo = request.getMessageProperties().getReplyToAddress();
    if (replyTo == null) {
        if (this.responseAddress == null && this.responseExchange != null) {
            this.responseAddress = new Address(this.responseExchange, this.responseRoutingKey);
        }
        if (result instanceof ResultHolder) {
            replyTo = evaluateReplyTo(request, source, result, ((ResultHolder) result).sendTo);
        } else if (this.responseExpression != null) {
            replyTo = evaluateReplyTo(request, source, result, this.responseExpression);
        } else if (this.responseAddress == null) {
            throw new AmqpException("Cannot determine ReplyTo message property value: "
                    + "Request message does not contain reply-to property, "
                    + "and no default response Exchange was set.");
        } else {
            replyTo = this.responseAddress;
        }
    }
    return replyTo;
}