Skip to content

Commit

Permalink
[ServiceBus] Reading TTL as the difference between absoluteexpirytime…
Browse files Browse the repository at this point in the history
… and creationtime (#12225)

TTL field in the message header is of type unsigned integer, so it cannot support TTL values
larger than 50 days when converted to milliseconds. So reading TTL as the difference between AbsoluteExpiryTime and CreationTime properties on the AMQP message.
  • Loading branch information
yvgopal authored May 26, 2020
1 parent 27053f8 commit e2f8099
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public static AmqpMessage SBMessageToAmqpMessage(SBMessage sbMessage)

if (sbMessage.TimeToLive != TimeSpan.MaxValue)
{
amqpMessage.Header.Ttl = (uint)sbMessage.TimeToLive.TotalMilliseconds;
amqpMessage.Header.Ttl = sbMessage.TimeToLive.TotalMilliseconds < UInt32.MaxValue ? (uint)sbMessage.TimeToLive.TotalMilliseconds : UInt32.MaxValue;
amqpMessage.Properties.CreationTime = DateTime.UtcNow;

if (AmqpConstants.MaxAbsoluteExpiryTime - amqpMessage.Properties.CreationTime.Value > sbMessage.TimeToLive)
Expand Down Expand Up @@ -274,6 +274,12 @@ public static SBMessage AmqpMessageToSBMessage(AmqpMessage amqpMessage, bool isP
{
sbMessage.ReplyToSessionId = amqpMessage.Properties.ReplyToGroupId;
}

if (amqpMessage.Properties.CreationTime.HasValue && amqpMessage.Properties.AbsoluteExpiryTime.HasValue)
{
// Overwrite TimeToLive from AbsoluteExpiryTime
sbMessage.TimeToLive = amqpMessage.Properties.AbsoluteExpiryTime.Value - amqpMessage.Properties.CreationTime.Value;
}
}

// Do application properties before message annotations, because the application properties
Expand Down

0 comments on commit e2f8099

Please sign in to comment.