当前位置: 首页>>代码示例>>Java>>正文


Java MessageProperties.setTimestamp方法代码示例

本文整理汇总了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;
}
 
开发者ID:MaxxtonGroup,项目名称:async-amqp-messaging,代码行数:28,代码来源:CommunicationController.java

示例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();
	}
	
}
 
开发者ID:sshcherbakov,项目名称:cf-service-tester,代码行数:45,代码来源:AmqpTestMessagePublisher.java


注:本文中的org.springframework.amqp.core.MessageProperties.setTimestamp方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。