Skip to content

Commit e8126f2

Browse files
afprtclrbordingramonsmits
authored
Handling routing keys with dots in delay delivery (#1609) (#1612)
Co-authored-by: Brandon Ording <[email protected]> Co-authored-by: Ramon Smits <[email protected]>
1 parent 7ad12e7 commit e8126f2

File tree

3 files changed

+4
-2
lines changed

3 files changed

+4
-2
lines changed

src/NServiceBus.Transport.RabbitMQ.CommandLine.Tests/MigrateDelayedMessages/When_migrating_a_delayed_message.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public class When_migrating_a_delayed_message
1313
[TestCase(128, new int[] { 2022, 5, 6, 12, 0, 0 }, "0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.1.0.0.0.0.0.0.0.destination", new int[] { 2022, 5, 6, 12, 0, 30 }, "destination", "0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.1.1.0.0.0.1.0.destination", 6)]
1414
[TestCase(86400, new int[] { 2022, 5, 6, 12, 0, 0 }, "0.0.0.0.0.0.0.0.0.0.0.1.0.1.0.1.0.0.0.1.1.0.0.0.0.0.0.0.destination", new int[] { 2022, 5, 7, 0, 0, 0 }, "destination", "0.0.0.0.0.0.0.0.0.0.0.0.1.0.1.0.1.0.0.0.1.1.0.0.0.0.0.0.destination", 15)]
1515
[TestCase(604800, new int[] { 2022, 5, 6, 12, 0, 0 }, "0.0.0.0.0.0.0.0.1.0.0.1.0.0.1.1.1.0.1.0.1.0.0.0.0.0.0.0.destination", new int[] { 2022, 5, 9, 12, 0, 0 }, "destination", "0.0.0.0.0.0.0.0.0.1.0.1.0.1.0.0.0.1.1.0.0.0.0.0.0.0.0.0.destination", 18)]
16+
[TestCase(604800, new int[] { 2022, 5, 6, 12, 0, 0 }, "0.0.0.0.0.0.0.0.1.0.0.1.0.0.1.1.1.0.1.0.1.0.0.0.0.0.0.0.destination.with.dots.in.name", new int[] { 2022, 5, 9, 12, 0, 0 }, "destination.with.dots.in.name", "0.0.0.0.0.0.0.0.0.1.0.1.0.1.0.0.0.1.1.0.0.0.0.0.0.0.0.0.destination.with.dots.in.name", 18)]
1617
public void Should_generate_the_correct_routing_key(int originalDelayInSeconds, int[] originalTimeSentValues, string originalRoutingKey, int[] utcNowValues, string expectedDestination, string expectedRoutingKey, int expectedDelayLevel)
1718
{
1819
var originalTimeSent = GetDateTimeOffsetFromValues(originalTimeSentValues);

src/NServiceBus.Transport.RabbitMQ.CommandLine/Commands/Delays/DelaysMigrateCommand.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class DelaysMigrateCommand(BrokerConnection brokerConnection, IRoutingTopology r
1212
const string poisonMessageQueue = "delays-migrate-poison-messages";
1313
const string timeSentHeader = "NServiceBus.TimeSent";
1414
const string dateTimeOffsetWireFormat = "yyyy-MM-dd HH:mm:ss:ffffff Z";
15+
const int indexStartOfDestinationQueue = DelayInfrastructure.MaxNumberOfBitsToUse * 2;
1516

1617
public static Command CreateCommand()
1718
{
@@ -143,7 +144,7 @@ public static (string DestinationQueue, string NewRoutingKey, int NewDelayLevel)
143144
{
144145
var originalDeliveryDate = timeSent.AddSeconds(delayInSeconds);
145146
var newDelayInSeconds = Convert.ToInt32(originalDeliveryDate.Subtract(utcNow).TotalSeconds);
146-
var destinationQueue = currentRoutingKey.Substring(currentRoutingKey.LastIndexOf('.') + 1);
147+
var destinationQueue = currentRoutingKey[indexStartOfDestinationQueue..];
147148
var newRoutingKey = DelayInfrastructure.CalculateRoutingKey(newDelayInSeconds, destinationQueue, out int newDelayLevel);
148149

149150
return (destinationQueue, newRoutingKey, newDelayLevel);

src/NServiceBus.Transport.RabbitMQ/DelayedDelivery/DelayInfrastructure.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace NServiceBus.Transport.RabbitMQ
1212

1313
static class DelayInfrastructure
1414
{
15-
const int MaxNumberOfBitsToUse = 28;
15+
public const int MaxNumberOfBitsToUse = 28;
1616

1717
public const int MaxLevel = MaxNumberOfBitsToUse - 1;
1818
public const int MaxDelayInSeconds = (1 << MaxNumberOfBitsToUse) - 1;

0 commit comments

Comments
 (0)