コード例 #1
0
        public void Should_return_correct_routing_key_based_on_delay(int delayInSeconds, string address, string expectedRoutingKey, int expectedStartingDelayLevel)
        {
            var result = DelayInfrastructure.CalculateRoutingKey(delayInSeconds, address, out var startingDelayLevel);

            Assert.That(result, Is.EqualTo(expectedRoutingKey));
            Assert.That(startingDelayLevel, Is.EqualTo(expectedStartingDelayLevel));
        }
コード例 #2
0
        public void Should_return_routing_key_with_delay_zero_seconds_for_negative_delay()
        {
            var result = DelayInfrastructure.CalculateRoutingKey(-123, "some-address", out var startingDelayLevel);

            Assert.That(result, Is.EqualTo("0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.some-address"));
            Assert.That(startingDelayLevel, Is.EqualTo(0));
        }
コード例 #3
0
        public static (string DestinationQueue, string NewRoutingKey, int NewDelayLevel) GetNewRoutingKey(int delayInSeconds, DateTimeOffset timeSent, string currentRoutingKey, DateTimeOffset utcNow)
        {
            var originalDeliveryDate = timeSent.AddSeconds(delayInSeconds);
            var newDelayInSeconds    = Convert.ToInt32(originalDeliveryDate.Subtract(utcNow).TotalSeconds);
            var destinationQueue     = currentRoutingKey.Substring(currentRoutingKey.LastIndexOf('.') + 1);
            var newRoutingKey        = DelayInfrastructure.CalculateRoutingKey(newDelayInSeconds, destinationQueue, out int newDelayLevel);

            return(destinationQueue, newRoutingKey, newDelayLevel);
        }