Skip to content

Commit 65ce392

Browse files
afprtclrbordingramonsmits
authored
Handling routing keys with dots in delay delivery (#1609) (#1615)
Co-authored-by: Brandon Ording <bording@gmail.com> Co-authored-by: Ramon Smits <ramon.smits@gmail.com>
1 parent 57bed54 commit 65ce392

File tree

4 files changed

+7
-5
lines changed

4 files changed

+7
-5
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
include:
2121
- os: windows-2019
2222
name: Windows
23-
- os: ubuntu-20.04
23+
- os: ubuntu-22.04
2424
name: Linux
2525
fail-fast: false
2626
steps:

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
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
{
@@ -142,7 +143,7 @@ public static (string DestinationQueue, string NewRoutingKey, int NewDelayLevel)
142143
{
143144
var originalDeliveryDate = timeSent.AddSeconds(delayInSeconds);
144145
var newDelayInSeconds = Convert.ToInt32(originalDeliveryDate.Subtract(utcNow).TotalSeconds);
145-
var destinationQueue = currentRoutingKey.Substring(currentRoutingKey.LastIndexOf('.') + 1);
146+
var destinationQueue = currentRoutingKey[indexStartOfDestinationQueue..];
146147
var newRoutingKey = DelayInfrastructure.CalculateRoutingKey(newDelayInSeconds, destinationQueue, out int newDelayLevel);
147148

148149
return (destinationQueue, newRoutingKey, newDelayLevel);

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88

99
static class DelayInfrastructure
1010
{
11-
const int maxNumberOfBitsToUse = 28;
11+
public const int MaxNumberOfBitsToUse = 28;
1212

13-
public const int MaxLevel = maxNumberOfBitsToUse - 1;
14-
public const int MaxDelayInSeconds = (1 << maxNumberOfBitsToUse) - 1;
13+
public const int MaxLevel = MaxNumberOfBitsToUse - 1;
14+
public const int MaxDelayInSeconds = (1 << MaxNumberOfBitsToUse) - 1;
1515
public const string DelayHeader = "NServiceBus.Transport.RabbitMQ.DelayInSeconds";
1616
public const string XDeathHeader = "x-death";
1717
public const string XFirstDeathExchangeHeader = "x-first-death-exchange";

0 commit comments

Comments
 (0)