in iothub/service/src/Messaging/Models/MessageConverter.cs [124:188]
public static void UpdateAmqpMessageHeadersAndProperties(AmqpMessage amqpMessage, Message data, bool copyUserProperties = true)
{
amqpMessage.Properties.MessageId = data.MessageId;
if (data.To != null)
{
amqpMessage.Properties.To = data.To;
}
if (!data.ExpiryTimeUtc.Equals(default))
{
amqpMessage.Properties.AbsoluteExpiryTime = data.ExpiryTimeUtc;
}
if (data.CorrelationId != null)
{
amqpMessage.Properties.CorrelationId = data.CorrelationId;
}
if (data.UserId != null)
{
amqpMessage.Properties.UserId = new ArraySegment<byte>(Encoding.UTF8.GetBytes(data.UserId));
}
if (amqpMessage.ApplicationProperties == null)
{
amqpMessage.ApplicationProperties = new ApplicationProperties();
}
if (data.SystemProperties.TryGetValue(MessageSystemPropertyNames.Ack, out object propertyValue))
{
amqpMessage.ApplicationProperties.Map["iothub-ack"] = (string)propertyValue;
}
if (data.SystemProperties.TryGetValue(MessageSystemPropertyNames.MessageSchema, out propertyValue))
{
amqpMessage.ApplicationProperties.Map[MessageSystemPropertyNames.MessageSchema] = (string)propertyValue;
}
if (data.SystemProperties.TryGetValue(MessageSystemPropertyNames.CreationTimeUtc, out propertyValue))
{
amqpMessage.ApplicationProperties.Map[MessageSystemPropertyNames.CreationTimeUtc] = ((DateTime)propertyValue).ToString("o", CultureInfo.InvariantCulture); // Convert to string that complies with ISO 8601
}
if (data.SystemProperties.TryGetValue(MessageSystemPropertyNames.ContentType, out propertyValue))
{
amqpMessage.Properties.ContentType = (string)propertyValue;
}
if (data.SystemProperties.TryGetValue(MessageSystemPropertyNames.ContentEncoding, out propertyValue))
{
amqpMessage.Properties.ContentEncoding = (string)propertyValue;
}
if (copyUserProperties && data.Properties.Count > 0)
{
foreach (KeyValuePair<string, string> pair in data.Properties)
{
if (TryGetAmqpObjectFromNetObject(pair.Value, MappingType.ApplicationProperty, out object amqpObject))
{
amqpMessage.ApplicationProperties.Map[pair.Key] = amqpObject;
}
}
}
}