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

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

Introduction

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

Prototype

public void setTimestamp(Date timestamp) 

Source Link

Usage

From source file:weChat.amqp.RpcTest.java

/**
 * Sends a message to a service that upcases the String and returns as a
 * reply using a {@link RabbitTemplate} configured with a fixed reply queue
 * and reply listener, configured with JavaConfig.
 */// w ww  .  jav a 2s.  c  om
@Test
public void test() {
    AmqpReqParam param = new AmqpReqParam();
    param.setCmdid("WJ007");
    param.setCompanycode("01103");
    param.setWechatpubinfoid(1);
    BaseDto dto = new BaseDto();
    dto.put("cardnum", "5000011");
    param.setParams(dto);
    //String corrId = UUID.randomUUID().toString();
    String corrId = FixedReplyQueueConfig.responseQueue;
    Object resp = rabbitTemplate.convertSendAndReceive(FixedReplyQueueConfig.routing, param, (message) -> {
        MessageProperties properities = message.getMessageProperties();

        System.out.println("corrId:" + corrId);
        properities.setCorrelationId(corrId.getBytes());
        properities.setDeliveryMode(MessageDeliveryMode.NON_PERSISTENT);
        properities.setTimestamp(new Date());
        long currentTimeMillis = System.currentTimeMillis();
        properities.setMessageId(String.valueOf(currentTimeMillis));
        properities.setExpiration(String.valueOf(50000));
        properities.setContentEncoding(corrId);

        return message;
    });
    System.out.println("?" + resp);
}

From source file:weChat.amqp.JavaConfigFixedReplyQueueTests.java

/**
 * Sends a message to a service that upcases the String and returns as a
 * reply using a {@link RabbitTemplate} configured with a fixed reply queue
 * and reply listener, configured with JavaConfig.
 *//* w  w  w.j a  v a2  s .c om*/
@Test
public void test() {
    AmqpReqParam param = new AmqpReqParam();
    param.setCmdid("WJ007");
    param.setCompanycode("00111");
    param.setWechatpubinfoid(1);
    BaseDto dto = new BaseDto();
    dto.put("cardnum", "5000028");
    param.setParams(dto);
    AmqpRespParam resp = (AmqpRespParam) rabbitTemplate.convertSendAndReceive(param, (message) -> {
        MessageProperties properities = message.getMessageProperties();
        String corrId = UUID.randomUUID().toString();
        properities.setCorrelationId(corrId.getBytes());
        properities.setDeliveryMode(MessageDeliveryMode.NON_PERSISTENT);
        properities.setTimestamp(new Date());
        long currentTimeMillis = System.currentTimeMillis();
        properities.setMessageId(String.valueOf(currentTimeMillis));

        return message;
    });
    System.out.println(resp);
}

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 w  ww. j  a v  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;
}