public MessageProperties toMessageProperties(
     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()) {
       String key = entry.getKey();
       if (MessageProperties.X_DELAY.equals(key)) {
         Object value = entry.getValue();
         if (value instanceof Integer) {
           target.setReceivedDelay((Integer) value);
         }
       } else {
         target.setHeader(key, convertLongStringIfNecessary(entry.getValue(), charset));
       }
     }
   }
   target.setTimestamp(source.getTimestamp());
   target.setMessageId(source.getMessageId());
   target.setReceivedUserId(source.getUserId());
   target.setAppId(source.getAppId());
   target.setClusterId(source.getClusterId());
   target.setType(source.getType());
   Integer deliveryMode = source.getDeliveryMode();
   if (deliveryMode != null) {
     target.setReceivedDeliveryMode(MessageDeliveryMode.fromInt(deliveryMode));
   }
   target.setDeliveryMode(null);
   target.setExpiration(source.getExpiration());
   target.setPriority(source.getPriority());
   target.setContentType(source.getContentType());
   target.setContentEncoding(source.getContentEncoding());
   String correlationId = source.getCorrelationId();
   if (StringUtils.hasText(correlationId)) {
     target.setCorrelationId(source.getCorrelationId());
   }
   String replyTo = source.getReplyTo();
   if (replyTo != null) {
     target.setReplyTo(replyTo);
   }
   if (envelope != null) {
     target.setReceivedExchange(envelope.getExchange());
     target.setReceivedRoutingKey(envelope.getRoutingKey());
     target.setRedelivered(envelope.isRedeliver());
     target.setDeliveryTag(envelope.getDeliveryTag());
   }
   return target;
 }
Beispiel #2
0
 public static MessageProperties valueOf(BasicProperties bp) {
   MessageProperties mp = new MessageProperties();
   mp.setAppId(bp.getAppId());
   mp.setClusterId(bp.getClusterId());
   mp.setContentEncoding(bp.getContentEncoding());
   mp.setContentType(bp.getContentType());
   mp.setCorrelationId(bp.getCorrelationId());
   mp.setDeliveryMode(bp.getDeliveryMode());
   mp.setExpiration(bp.getExpiration());
   mp.setHeaders(bp.getHeaders());
   mp.setMessageId(bp.getMessageId());
   mp.setPriority(bp.getPriority());
   mp.setReplyTo(bp.getReplyTo());
   mp.setTimestamp(bp.getTimestamp());
   mp.setType(bp.getType());
   mp.setUserId(bp.getUserId());
   return mp;
 }