本文整理汇总了Java中org.springframework.amqp.core.MessageProperties.setTimestamp方法的典型用法代码示例。如果您正苦于以下问题:Java MessageProperties.setTimestamp方法的具体用法?Java MessageProperties.setTimestamp怎么用?Java MessageProperties.setTimestamp使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.amqp.core.MessageProperties
的用法示例。
在下文中一共展示了MessageProperties.setTimestamp方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: packAndSend
import org.springframework.amqp.core.MessageProperties; //导入方法依赖的package包/类
/**
* Convert a message to the appropriate Message class and send it using a response correlationId.
*
* @param receiver
* the receiver of the message.
* @param baseMessage
* the message to be send.
* @param responseTo
* correlationId where the message is a response to.
* @return outcome of the send method. An valid UUID if the message was send correctly, null if it was not.
*/
public String packAndSend(String receiver, BaseMessage baseMessage, String responseTo)
{
MessageProperties properties = new MessageProperties();
String uuid = responseTo == null || responseTo == "" ? UUID.randomUUID().toString() : responseTo;
properties.setCorrelationId(uuid.getBytes());
properties.setTimestamp(new Date());
byte[] messageBytes = MessageSerializer.serialize(baseMessage);
Message message = new Message(messageBytes, properties);
if (objSender.sendMessage(receiver, message))
{
return uuid;
}
return null;
}
示例2: publish
import org.springframework.amqp.core.MessageProperties; //导入方法依赖的package包/类
@Override
@Timed
public void publish() {
if(rabbitTemplate == null) {
log.debug("RabbitMQ Service unavailable");
stateService.setRabbitDown();
return;
}
Date now = new Date();
String messageId = getMessageId();
String messagePayload = getMessageBody(messageId, now);
MessageProperties messageProperties = new MessageProperties();
messageProperties.setAppId(instanceName);
messageProperties.setMessageId(messageId);
messageProperties.setTimestamp(now);
Message amqpMsg = MessageBuilder
.withBody(messagePayload.getBytes())
.andProperties(messageProperties)
.build();
try {
rabbitTemplate.send(rabbitExchangeName, rabbitQueueName,
amqpMsg, new CorrelationData(messageId));
log.info("{} [{}] {}",
instanceName,
amqpMsg.getMessageProperties().getMessageId(),
messagePayload);
stateService.setRabbitUp();
}
catch(AmqpException ex) {
log.warn("({}) Publish of [{}] to RabbitMQ has failed",
utils.getPublishedKey(consistencyChecker.getIndex()), messageId);
stateService.setRabbitDown();
}
}