Example usage for org.springframework.amqp.core MessageProperties setReplyTo

List of usage examples for org.springframework.amqp.core MessageProperties setReplyTo

Introduction

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

Prototype

public void setReplyTo(String replyTo) 

Source Link

Usage

From source file:org.springframework.amqp.rabbit.AsyncRabbitTemplate.java

private String getOrSetCorrelationIdAndSetReplyTo(Message message) {
    String correlationId;/*from  ww  w .  ja  va 2 s  . com*/
    MessageProperties messageProperties = message.getMessageProperties();
    Assert.notNull(messageProperties, "the message properties cannot be null");
    String currentCorrelationId = messageProperties.getCorrelationId();
    if (!StringUtils.hasText(currentCorrelationId)) {
        correlationId = UUID.randomUUID().toString();
        messageProperties.setCorrelationId(correlationId);
        Assert.isNull(messageProperties.getReplyTo(), "'replyTo' property must be null");
    } else {
        correlationId = currentCorrelationId;
    }
    messageProperties.setReplyTo(this.replyAddress);
    return correlationId;
}

From source file:org.springframework.amqp.rabbit.core.AsyncRabbitTemplate.java

private String getOrSetCorrelationIdAndSetReplyTo(Message message) {
    String correlationId;//from   w  ww .jav a 2s . c om
    MessageProperties messageProperties = message.getMessageProperties();
    Assert.notNull(messageProperties, "the message properties cannot be null");
    byte[] currentCorrelationId = messageProperties.getCorrelationId();
    if (currentCorrelationId == null) {
        correlationId = UUID.randomUUID().toString();
        messageProperties.setCorrelationId(correlationId.getBytes(this.charset));
        Assert.isNull(messageProperties.getReplyTo(), "'replyTo' property must be null");
    } else {
        correlationId = new String(currentCorrelationId, this.charset);
    }
    messageProperties.setReplyTo(this.replyAddress);
    return correlationId;
}

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());
        }/*from  ww  w . j  av  a 2  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;
}