List of usage examples for org.springframework.amqp.core MessageProperties getTimestamp
public Date getTimestamp()
From source file:org.springframework.amqp.rabbit.log4j.listener.AmqpLogMessageConverter.java
@Override public Object fromMessage(Message message) throws MessageConversionException { AmqpLogMessage content = null;/*from w ww . ja v a2 s. c o m*/ MessageProperties properties = message.getMessageProperties(); if (properties != null) { String applicationId = properties.getAppId(); Date timestamp = properties.getTimestamp(); Map<String, Object> headers = properties.getHeaders(); if (CollectionUtils.isEmpty(headers)) { log.warn("Retrieved log message properties should contain headers"); return null; } if (!headers.containsKey(AmqpAppender.CATEGORY_NAME)) { log.warn(AmqpAppender.CATEGORY_NAME + " - is expected in log message properties headers"); return null; } if (!headers.containsKey(AmqpAppender.CATEGORY_LEVEL)) { log.warn(AmqpAppender.CATEGORY_LEVEL + " - is expected in log message properties headers"); return null; } String logger = (String) headers.get(AmqpAppender.CATEGORY_NAME); String level = (String) headers.get(AmqpAppender.CATEGORY_LEVEL); content = new AmqpLogMessage(logger, level, new String(message.getBody()), timestamp.getTime(), applicationId); } else { log.warn("Retrieved log message should contain properties"); } return content; }
From source file:org.springframework.amqp.rabbit.support.RabbitUtils.java
public static BasicProperties extractBasicProperties(Message message, String charset) { if (message == null || message.getMessageProperties() == null) { return null; }/*from w ww . ja v a 2s . c o m*/ MessageProperties source = message.getMessageProperties(); BasicProperties target = new BasicProperties(); target.setHeaders(source.getHeaders()); target.setTimestamp(source.getTimestamp()); target.setMessageId(source.getMessageId()); target.setUserId(source.getUserId()); target.setAppId(source.getAppId()); target.setClusterId(source.getClusterId()); target.setType(source.getType()); MessageDeliveryMode deliveryMode = source.getDeliveryMode(); if (deliveryMode != null) { target.setDeliveryMode(MessageDeliveryMode.toInt(deliveryMode)); } target.setExpiration(source.getExpiration()); target.setPriority(source.getPriority()); target.setContentType(source.getContentType()); target.setContentEncoding(source.getContentEncoding()); byte[] correlationId = source.getCorrelationId(); if (correlationId != null && correlationId.length > 0) { try { target.setCorrelationId(new String(correlationId, charset)); } catch (UnsupportedEncodingException ex) { throw new AmqpUnsupportedEncodingException(ex); } } Address replyTo = source.getReplyTo(); if (replyTo != null) { target.setReplyTo(replyTo.toString()); } return target; }